#include "QuoteLvData.h"
//#include "StringTools.h"
//#include "ColorTools.h"
#include "XmlTools.h"
//#include "DrawTools.h"

void QuoteDataLV_PackAskHead(QUOTELV_HEAD *pAskHead, char *pDst)
{
	char *p = pDst;
	
	//包类型
	p[0] = pAskHead->type;
	p+=1;
	//顺序号
	ShortToBytes(pAskHead->seq, p);
	p+=2;
	//版本号
	p[0] = pAskHead->ver;
	p+=1;
	//类型
	p[0] = pAskHead->funcid;
	p+=1;
	//终端语言
	p[0] = pAskHead->language;
	p+=1;
	//订阅Id
	ShortToBytes(pAskHead->subid, p);
	p+=2;
	
}

void QuoteDataLV_ParseDictData(char *aSrc, QUOTELV_DICT_RES *aDictRes)
{
	if (aDictRes->pDictdata) {
		Tools_Free((void **)&aDictRes->pDictdata);
	}
	
	if (aDictRes->pVerData) {
		Tools_Free((void **)&aDictRes->pVerData);
	}
	
	char *pSrc = (char*)aSrc;
	int nPos = 0;
	memset(aDictRes,0,sizeof(QUOTELV_DICT_RES));
	aDictRes->sVerLen = BytesToShort(pSrc,nPos);
	nPos += 2;
	aDictRes->pVerData = (char *)Tools_Malloc(aDictRes->sVerLen + 1);
	memcpy(aDictRes->pVerData,pSrc+nPos,aDictRes->sVerLen);
	nPos += aDictRes->sVerLen;

	aDictRes->sCount = BytesToShort(pSrc,nPos);
	nPos += 2;
	
	if (aDictRes->sCount > 0) {
		aDictRes->nDictLen = aDictRes->sCount * QUOTELV_DICT_POINT_LEN;
		aDictRes->pDictdata = (char *) Tools_Malloc(aDictRes->nDictLen + 1);
		memcpy(aDictRes->pDictdata, pSrc+nPos,aDictRes->nDictLen);
	}
}

void QuoteDataLV_ParseStockInfo(char *aSrc, CODELV_INFO *aInfo, int *nPos)
{
	memset(aInfo,0,CODELV_INFO_LEN);
	char *pSrc = (char*)aSrc;
	//股票代码6字节
	memcpy(aInfo->code, pSrc, 6);
	pSrc+=6;
	
	//股票名称24字节
	memcpy(aInfo->name, pSrc, 24);
	pSrc+=24;
	
	//保留小数位数
	aInfo->decNum = pSrc[0];
	pSrc+=1;
	//市场
	aInfo->market = pSrc[0];
	pSrc+=1;
	//类型
	aInfo->style   = pSrc[0];
	pSrc+=1;
	
	*nPos += CODELV_INFO_LEN;
	
}

void QuoteDataLV_ParseStockPoint(char *aSrc, QUOTELV_STOCK_POINT *aStock, int aIndex, int *aPos)
{
	switch(aIndex)
	{
	case QUOTELV_CUSTOM_CODEINFO:	QuoteDataLV_ParseStockInfo(aSrc+(*aPos),&aStock->codeinfo,aPos); break;
			
	case QUOTELV_CUSTOM_CODE: memset(aStock->code,0,CODELV_LEN+1); memcpy(aStock->code,aSrc+*aPos,CODELV_LEN); *aPos += CODELV_LEN; aStock->maketId = aSrc[*aPos]; *aPos += 1; break;
	case QUOTELV_CUSTOM_DATE: aStock->nDate = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_TIME: aStock->nTime = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_PRECLOSE: aStock->fPre = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_OPEN: aStock->fOpen = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_HIGH: aStock->fHigh = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_LOW: aStock->fLow = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_NOW: aStock->fCur = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_VOLUME: aStock->lVol = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_CURVOLUME: aStock->lCurVol = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_AMOUNT: aStock->lSum = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP1: aStock->fBid = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP1: aStock->fAsk = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV1: aStock->lBidVol1 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV1: aStock->lAskVol1 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP2: aStock->fBidPri2 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP2: aStock->fAskPri2 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV2: aStock->lBidVol2 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV2: aStock->lAskVol2 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP3: aStock->fBidPri3 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP3: aStock->fAskPri3 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV3: aStock->lBidVol3 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV3: aStock->lAskVol3 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP4: aStock->fBidPri4 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP4: aStock->fAskPri4 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV4: aStock->lBidVol4 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV4: aStock->lAskVol4 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP5: aStock->fBidPri5 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP5: aStock->fAskPri5 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV5: aStock->lBidVol5 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV5: aStock->lAskVol5 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_REDV: aStock->lOutSide = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_VR: aStock->nVolRate = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_DR: aStock->nDifRange = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_DIFF: aStock->fDiff = BytesToFloat(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_5MDIFF: aStock->n5DifRange = BytesToInt(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_HS: aStock->nSwap = BytesToInt(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_WB: aStock->nWeiBi = BytesToInt(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_WC: aStock->lWeiCha = BytesToLong64(aSrc,*aPos); *aPos += 8;		break;
	case QUOTELV_CUSTOM_PE: aStock->nExePrice = BytesToInt(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_AMP: aStock->nAmplitude = BytesToInt(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_AVP: aStock->fAvgPrice = BytesToFloat(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_5DA: aStock->n5DaysAvgVolume = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP6: aStock->fBidPri6 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP6: aStock->fAskPri6 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV6: aStock->lBidVol6 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV6: aStock->lAskVol6 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP7: aStock->fBidPri7 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP7: aStock->fAskPri7 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV7: aStock->lBidVol7 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV7: aStock->lAskVol7 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP8: aStock->fBidPri8 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP8: aStock->fAskPri8 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV8: aStock->lBidVol8 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV8: aStock->lAskVol8 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP9: aStock->fBidPri9 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP9: aStock->fAskPri9 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV9: aStock->lBidVol9 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV9: aStock->lAskVol9 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_SELLP10: aStock->fBidPri10 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BUYP10: aStock->fAskPri10 = BytesToFloat(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SELLV10: aStock->lBidVol10 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BUYV10: aStock->lAskVol10 = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_ENDPOINT: aStock->nCurTime = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_UPNUM: aStock->upNum = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_SAMENUM: aStock->SameNum = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_DOWNNUM: aStock->DownNum = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_OLDUPNUM: aStock->OldUpNum = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_OLDSAMENUM: aStock->OldSameNum = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_OLDDOWNNUM: aStock->OldDownNum = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_RN: aStock->Rn = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_RN1: aStock->Rn1 = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_DN: aStock->Dn = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_DN1: aStock->Dn1 = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_RD: aStock->Rd = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_LI: aStock->lIndex = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_RDP: aStock->Rdp = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_STIME: aStock->sTime = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BLOCKID: aStock->BlockId = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_STOCKNUM: aStock->StockNum = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_WPRI: aStock->nWeekPre = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_WZDF: aStock->nWeekZdf = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_WKPJ: aStock->nWeekOpen = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_WHS: aStock->nWeekHS = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_WUP: aStock->nWeekHS = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_WDOWN: aStock->nWeekHS = BytesToShort(aSrc,*aPos); *aPos += 2;	break;
	case QUOTELV_CUSTOM_ZJL: aStock->nWeekZjl = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_ZJF: aStock->nWeekZjf = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_GZD: aStock->nWeekGzd = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_5ZDF: aStock->nWeek5Zdf = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_10ZDF: aStock->nWeek10Zdf = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_SPJ: aStock->nWeekSp = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_BLOCK_ID_STOCK: aStock->BlockIdStock = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_CUSTOM_BLOCK_NAME_STOCK:memset(aStock->BlockNameStock,0,NAMELV_LEN+1); memcpy(aStock->BlockNameStock,aSrc+*aPos,NAMELV_LEN); *aPos += NAMELV_LEN;break;
    case QUOTELV_CUSTOM_BLOCK_DR: aStock->nBlockDifRange = BytesToInt(aSrc,*aPos); *aPos += 4;	break;
	case QUOTELV_CUSTOM_TOTALBUY: aStock->lTotalBidQty = BytesToLong64(aSrc,*aPos); *aPos += 8; break;
	case QUOTELV_CUSTOM_TOTALSELL: aStock->lTotalAskQty = BytesToLong64(aSrc,*aPos);	*aPos += 8; break;
	case QUOTELV_CUSTOM_TOTALSHARE: aStock->lTotalShare = BytesToLong64(aSrc,*aPos); *aPos += 8; break;
	case QUOTELV_CUSTOM_ASSETPS: aStock->nNetAssetPS = BytesToFloat(aSrc,*aPos); *aPos += 4; break;
	case QUOTELV_CUSTOM_EPS: aStock->nEps = BytesToInt(aSrc,*aPos); *aPos += 4;		break;
	case QUOTELV_CUSTOM_FS: aStock->lFloatShare = BytesToLong64(aSrc,*aPos); *aPos += 8;	break;
	case QUOTELV_RISELIMITPRICE: aStock->nRiseLimitPrice = BytesToFloat(aSrc,*aPos); *aPos += 4; break;
  case QUOTELV_DECLIMITPRICE: aStock->nDecLimitPrice = BytesToFloat(aSrc,*aPos); *aPos += 4; break;
			///股指期货新增字段
	case QUOTELV_CUSTOM_PREOPENINTEREST:aStock->lPreOpenInterest = BytesToLong64(aSrc, *aPos); *aPos += 8; break;
	case QUOTELV_CUSTOM_OPENINTEREST:aStock->lOpenInterest = BytesToLong64(aSrc, *aPos); *aPos += 8; break;
	case QUOTELV_CUSTOM_SETTLEPRICE:aStock->fSettlePrice = BytesToFloat(aSrc, *aPos); *aPos += 4; break;
	case QUOTELV_CUSTOM_PRESETTLEPRICE:aStock->fPreSettlePrice = BytesToFloat(aSrc, *aPos); *aPos += 4; break;
	case QUOTELV_CUSTOM_PRICEDIFFER:aStock->fPriceDiffer = BytesToFloat(aSrc, *aPos); *aPos += 4; break;
	case QUOTELV_CUSTOM_PRICEDIFFERRATIO:aStock->fPriceDifferRatio = BytesToFloat(aSrc, *aPos); *aPos += 4; break;
	case QUOTELV_CUSTOM_INCREASEDPREINTEREST:aStock->nIncreasedOpenInterest = BytesToInt(aSrc, *aPos); *aPos += 4; break;
	case QUOTELV_CUSTOM_DAYPREINTEREST:aStock->lDayOpenInterest = BytesToLong64(aSrc, *aPos); *aPos += 8; break;
			
	default:
		break;
	}
}

void QuoteDataLV_ParseMinPoint(char *aSrc, QUOTELV_MIN_POINT *aMin, int aIndex, int *aPos, int nd, QUOTELV_MIN_POINT *aMinPre)
{
	switch(aIndex)
	{
	case QUOTELV_CUSTOM_MIN_PRI:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aMin->fPri = aMinPre->fPri+n/pow(10, nd);
			*aPos += l;
		}
			break;
	case QUOTELV_CUSTOM_MIN_SUM:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aMin->lSum = aMinPre->lSum + ll;
			*aPos += l;
		}
			break;
	case QUOTELV_CUSTOM_MIN_VOL:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aMin->lVol = aMinPre->lVol + ll;
			*aPos += l;
			
		}
			break;
	case QUOTELV_CUSTOM_MIN_AP: 
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aMin->fAvgPrice = aMinPre->fAvgPrice+n/10000.0;
			*aPos += l;
		}
			break;
	case QUOTELV_CUSTOM_MIN_TBV:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aMin->nTotalBuyVolume = aMinPre->nTotalBuyVolume + ll;
			*aPos += l;
			
		}
			break;
	case QUOTELV_CUSTOM_MIN_TSV:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aMin->nTotalSellVolume = aMinPre->nTotalSellVolume + ll;
			*aPos += l;
			
		}
			break;
	case QUOTELV_CUSTOM_MIN_RDP:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aMin->Rdp = aMinPre->Rdp+n;
			*aPos += l;
			
		}
			break;
	case QUOTELV_CUSTOM_MIN_OIT:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aMin->Oit = aMinPre->Oit + ll;
			*aPos += l;
		}
			break;
	default:
		break;
	}
}

//add xzm 非压缩分时分时点解析
void QuoteDataLV_ParseMinPoint2(char *aSrc, QUOTELV_MIN_POINT *aMin, int aIndex, int *aPos)
{
  switch(aIndex)
  {
    case QUOTELV_CUSTOM_MIN_PRI:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//
//      aMin->fPri = aMinPre->fPri+n/pow(10, nd);
//      *aPos += l;
      
//      int fPri = BytesToInt(aSrc, *aPos);
//      aMin->fPri =  fPri/10000.0;
      
      aMin->fPri =   BytesToInt(aSrc, *aPos)/10000.0;
      
      *aPos += 4;
    }
      break;
    case QUOTELV_CUSTOM_MIN_SUM:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aMin->lSum = aMinPre->lSum + ll;
//      *aPos += l;
      aMin->lSum = BytesToLong64(aSrc, *aPos);
      *aPos += 8;
    }
      break;
    case QUOTELV_CUSTOM_MIN_VOL:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aMin->lVol = aMinPre->lVol + ll;
//      *aPos += l;
      aMin->lVol = BytesToLong64(aSrc, *aPos);
      *aPos += 8;
    }
      break;
    case QUOTELV_CUSTOM_MIN_AP:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      
//      aMin->fAvgPrice = aMinPre->fAvgPrice+n/10000.0;
//      *aPos += l;
      aMin->fAvgPrice = BytesToInt(aSrc, *aPos)/10000.0;
      *aPos += 4;
    }
      break;
    case QUOTELV_CUSTOM_MIN_TBV:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aMin->nTotalBuyVolume = aMinPre->nTotalBuyVolume + ll;
//      *aPos += l;
      aMin->nTotalBuyVolume = BytesToLong64(aSrc, *aPos);
      *aPos += 8;
      
    }
      break;
    case QUOTELV_CUSTOM_MIN_TSV:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aMin->nTotalSellVolume = aMinPre->nTotalSellVolume + ll;
//      *aPos += l;
      aMin->nTotalSellVolume = BytesToLong64(aSrc, *aPos);
      *aPos += 8;
    }
      break;
    case QUOTELV_CUSTOM_MIN_RDP:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      
//      aMin->Rdp = aMinPre->Rdp+n;
//      *aPos += l;
      
      aMin->Rdp = BytesToShort(aSrc, *aPos);
      *aPos += 2;
      
    }
      break;
    case QUOTELV_CUSTOM_MIN_OIT:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aMin->Oit = aMinPre->Oit + ll;
//      *aPos += l;
      
      aMin->Oit = BytesToLong64(aSrc, *aPos);
      *aPos += 8;
    }
      break;
    default:
      break;
  }
}
//add end xzm 非压缩分时分时点解析


//lisz add 20110916 start
void QuoteDataLV_ParseLeve2MinPoint(char *aSrc,
                                    QUOTELV_LEVE2_MIN_POINT *aMin,
                                    int aIndex,
                                    int *aPos,
                                    QUOTELV_LEVE2_MIN_POINT *aMinPre)
{
	switch(aIndex)
	{
		case RQS_LV2_MIN_LITTLE_AMOUNT_DIFF:
    {
      long long ll=0;
			readRLong(aSrc+(*aPos), &ll);
			aMin->lLittleAmountDiff = aMinPre->lLittleAmountDiff + ll;
			*aPos += 3;
    }
			break;
		case RQS_LV2_MIN_MID_AMOUNT_DIFF:
    {
      long long ll=0;
			readRLong(aSrc+(*aPos), &ll);
			aMin->lMidAmountDiff = aMinPre->lMidAmountDiff + ll;
			*aPos += 3;
    }
			break;
		case RQS_LV2_MIN_BIG_AMOUNT_DIFF:
    {
      long long ll=0;
			readRLong(aSrc+(*aPos), &ll);
			aMin->lBigAmountDiff = aMinPre->lBigAmountDiff + ll;
			*aPos += 3;
    }
			break;
    case RQS_LV2_MIN_BIGGER_AMOUNT_DIFF:
    {
      long long ll=0;
			readRLong(aSrc+(*aPos), &ll);
			aMin->lBiggerAmountDiff = aMinPre->lBiggerAmountDiff + ll;
			*aPos += 3;
    }
			break;
    case RQS_LV2_MIN_MAIN_VOLUME_DIFF:
    {
      long long ll=0;
			readRLong(aSrc+(*aPos), &ll);
			aMin->lMainVolumeDiff = ll;
			*aPos += 3;
    }
			break;
	}
}
//lisz add 20110916 end

void QuoteDataLV_ParseKPoint(char *aSrc, QUOTELV_K_POINT *aK, int aIndex, int *aPos, int nd, QUOTELV_K_POINT *aKPre)
{
	switch(aIndex)
	{
		case QUOTELV_K_CUSTOM_DATE:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aK->nDate = aKPre->nDate+n;
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_OPEN:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aK->fOpen = aKPre->fOpen+n/pow(10, nd);
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_HIGH:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aK->fHigh = aKPre->fHigh+n/pow(10, nd);
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_LOW:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aK->fLow = aKPre->fLow+n/pow(10, nd);
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_CUR:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			
			aK->fCur = aKPre->fCur+n/pow(10, nd);
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_SUM:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aK->lSum = aKPre->lSum + ll;
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_VOL:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aK->lVol = aKPre->lVol + ll;
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_SWAP:
		{
			int n=0;
			int l=0;
			readInt(aSrc+(*aPos), &n, &l);
			//add by jason 换手固定放大10000
			//aK->fSwap = aKPre->fSwap+n/pow(10, nd);
			aK->fSwap = aKPre->fSwap+n/pow(10, 4);
			//end
			*aPos += l;
		}
			break;
		case QUOTELV_K_CUSTOM_KEYDATE:
		{
			long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aK->lKeyDate = aKPre->lKeyDate + ll;
			*aPos += l;
		}
			break;
		default:
			break;
	}
}

//add end xzm 20141215 非压缩K线点解析
void QuoteDataLV_ParseKPoint2(char *aSrc, QUOTELV_K_POINT *aK, int aIndex, int *aPos, int nd, QUOTELV_K_POINT *aKPre)
{
  switch(aIndex)
  {
    case QUOTELV_K_CUSTOM_DATE:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      
//      aK->nDate = aKPre->nDate+n;
//      *aPos += l;
      
      aK->nDate =   BytesToInt(aSrc, *aPos);
      
      *aPos += 4;
    }
      break;
    case QUOTELV_K_CUSTOM_OPEN:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      
//      aK->fOpen = aKPre->fOpen+n/pow(10, nd);
//      *aPos += l;
      
      aK->fOpen = (BytesToInt(aSrc, *aPos))/10000.0;
      
      *aPos += 4;
    }
      break;
    case QUOTELV_K_CUSTOM_HIGH:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      
//      aK->fHigh = aKPre->fHigh+n/pow(10, nd);
//      *aPos += l;
      
      aK->fHigh = (BytesToInt(aSrc, *aPos))/10000.0;
      
      *aPos += 4;
    }
      break;
    case QUOTELV_K_CUSTOM_LOW:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      
//      aK->fLow = aKPre->fLow+n/pow(10, nd);
//      *aPos += l;
      
      aK->fLow = (BytesToInt(aSrc, *aPos))/10000.0;
      
      *aPos += 4;
    }
      break;
    case QUOTELV_K_CUSTOM_CUR:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      
//      aK->fCur = aKPre->fCur+n/pow(10, nd);
//      *aPos += l;
      
      aK->fCur = (BytesToInt(aSrc, *aPos))/10000.0;
      
      *aPos += 4;
    }
      break;
    case QUOTELV_K_CUSTOM_SUM:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aK->lSum = aKPre->lSum + ll;
//      *aPos += l;
      
      aK->lSum =   BytesToLong64(aSrc, *aPos);
      
      *aPos += 8;
    }
      break;
    case QUOTELV_K_CUSTOM_VOL:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aK->lVol = aKPre->lVol + ll;
//      *aPos += l;
      
      aK->lVol =   BytesToLong64(aSrc, *aPos);
      
      *aPos += 8;
    }
      break;
    case QUOTELV_K_CUSTOM_SWAP:
    {
//      int n=0;
//      int l=0;
//      readInt(aSrc+(*aPos), &n, &l);
//      //add by jason 换手固定放大10000
//      //aK->fSwap = aKPre->fSwap+n/pow(10, nd);
//      aK->fSwap = aKPre->fSwap+n/pow(10, 4);
//      //end
//      *aPos += l;
      aK->fSwap = (BytesToInt(aSrc, *aPos))/10000.0;
      
      *aPos += 4;
    }
      break;
    case QUOTELV_K_CUSTOM_KEYDATE:
    {
//      long long ll=0;
//      int l = 0;
//      
//      readLong(aSrc+(*aPos), &ll, &l);
//      aK->lKeyDate = aKPre->lKeyDate + ll;
//      *aPos += l;
      
      aK->lKeyDate =   BytesToLong64(aSrc, *aPos);
      
      *aPos += 8;
    }
      break;
    default:
      break;
  }
}
//add end xzm 20141215 非压缩K线点解析

void QuoteDataLV_ParseLeve2KPoint(char *aSrc, QUOTELV_LEVE2_K_POINT *aK, int aIndex, int *aPos)
{
	switch(aIndex)
	{
		case RQS_LV2_RETAIL_BID_VOLUME:
    {
      readRLong(aSrc+(*aPos), &aK->lRetailBidVolume);
      *aPos += 3;
    }
			break;
		case RQS_LV2_RETAIL_BID_TRADE_COUNT:
    {
      readRLong(aSrc+(*aPos), &aK->lRetailBidTradeCount);
      *aPos += 3;
    }
			break;
		case RQS_LV2_MAIN_BID_VOLUME:
    {
      readRLong(aSrc+(*aPos), &aK->lMainBidVolume);
      *aPos += 3;
    }
			break;
		case RQS_LV2_MAIN_BID_AMOUNT:
    {
      readRLong(aSrc+(*aPos), &aK->lMainBidAmount);
      *aPos += 3;
    }
			break;
    case RQS_LV2_MAIN_BID_TRADE_COUNT:
    {
      readRLong(aSrc+(*aPos), &aK->lMainBidTradeCount);
      *aPos += 3;
    }
			break;
    case RQS_LV2_RETAIL_ASK_VOLUME:
    {
      readRLong(aSrc+(*aPos), &aK->lRetailAskVolume);
      *aPos += 3;
    }
			break;
    case RQS_LV2_RETAIL_ASK_TRADE_COUNT:
    {
      readRLong(aSrc+(*aPos), &aK->lRetailAskTradeCount);
      *aPos += 3;
    }
			break;
    case RQS_LV2_MAIN_ASK_VOLUME:
    {
      readRLong(aSrc+(*aPos), &aK->lMainAskVolume);
      *aPos += 3;
    }
			break;
    case RQS_LV2_MAIN_ASK_AMOUNT:
    {
      readRLong(aSrc+(*aPos), &aK->lMainAskAmount);
      *aPos += 3;
    }
			break;
    case RQS_LV2_MAIN_ASK_TRADE_COUNT:
    {
      readRLong(aSrc+(*aPos), &aK->lMainAskTradeCount);
      *aPos += 3;
    }
			break;
	}
}

void QuoteDataLV_ParseLeve2TrancKPoint(char *aSrc,
                                       QUOTELV_LEVE2_K_TRANC_POINT *aK,
                                       int aIndex,
                                       int *aPos,
                                       QUOTELV_LEVE2_K_TRANC_POINT *aKPre)
{
  int nc = 0;
  switch(aIndex)
	{
		case RQS_LV2_TRANC_MAIN_BID_VOLUME:
    {
      readRLong(aSrc+(*aPos), &aK->lMainBidVolume);
      *aPos += 3;
    }
			break;
		case RQS_LV2_TRANC_MAIN_ASK_VOLUME:
    {
			readRLong(aSrc+(*aPos), &aK->lMainAskVolume);
      *aPos += 3;
    }
			break;
		case RQS_LV2_TRANC_TOTAL_TRADE_COUNT:
    {
      long long ll=0;
			int l = 0;
			
			readLong(aSrc+(*aPos), &ll, &l);
			aK->lTotalTradeCount = aKPre->lTotalTradeCount + ll;
			*aPos += l;
    }
	}
}

void QuoteDataLV_ParseInfoPoint(char *aSrc, QUOTELV_STOCKINFO_POINT *aInfo)
{
	aInfo->pTitle = XmlTools_GetLeaf(aSrc,"title");
	aInfo->pUrl = XmlTools_GetLeaf(aSrc,"url");
	aInfo->pDate = XmlTools_GetLeaf(aSrc,"date");
}

void QuoteDataLV_ParsePriceData(char *aSrc, int aType, QUOTELV_PRICE_RES *aPriceRes)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	if (aType == QUOTE_LV_TYPE_ALL) {
		memset(aPriceRes,0,sizeof(QUOTELV_PRICE_RES));
	}
	
	int nPos = 0;
	int i = 0;
	aPriceRes->fdcount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for (; i<aPriceRes->fdcount; i++)
	{
		aPriceRes->fd[i] = BytesToShort(aSrc,nPos);
		nPos += 2;
	}
	

	for (i=0; i<aPriceRes->fdcount; i++)
	{ 
		QuoteDataLV_ParseStockPoint(aSrc,&aPriceRes->priceData,aPriceRes->fd[i],&nPos);
	
	}
	
	aPriceRes->priceData.lInSide = aPriceRes->priceData.lVol - aPriceRes->priceData.lOutSide;
	
}

void QuoteDataLV_ParseOwnData(char *aSrc, QUOTELV_OWN_RES *aOwnRes, short aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	if (aType == QUOTE_LV_TYPE_ALL)
	{
		memset(aOwnRes,0,sizeof(QUOTELV_OWN_RES));
	}
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	int m = 0;
	aOwnRes->fdcount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for (; i<aOwnRes->fdcount; i++)
	{
		aOwnRes->fd[i] = BytesToShort(aSrc,nPos);
		nPos += 2;
	}
	
	aOwnRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if(aType == QUOTE_LV_TYPE_ALL)			//如果是全包就是返回的总量
	{
		
		aOwnRes->nTotalCount = aOwnRes->nCount;
		
		for(i=0; i<aOwnRes->nCount; i++)
		{
			for (j=0; j<aOwnRes->fdcount; j++)
			{
				QuoteDataLV_ParseStockPoint(aSrc,&aOwnRes->ownData[i],aOwnRes->fd[j],&nPos);
			}
		}
	}
	else
	{
		QUOTELV_STOCK_POINT		tPoint;				//临时存储变量
		int len = sizeof(QUOTELV_STOCK_POINT);
		
		for(i=0; i<aOwnRes->nCount; i++)
		{
			
			memset(&tPoint,0,len);
			
			for (j=0; j<aOwnRes->fdcount; j++)
			{
				QuoteDataLV_ParseStockPoint(aSrc,&tPoint,aOwnRes->fd[j],&nPos);
			}
			
			for (m=0; m<aOwnRes->nTotalCount; m++)
			{
				if (strcmp(tPoint.code,aOwnRes->ownData[m].codeinfo.code) == 0)
				{
					int n = sizeof(CODELV_INFO);
					void *pd = &aOwnRes->ownData[m];
					void *ps = &tPoint;
					memcpy(pd+n,ps+n,len-n);
					break;
				}
			}
			
		}
	}
	
	
}

void QuoteDataLV_ParseOwnAllData(char *aSrc, QUOTELV_OWNALL_RES *aOwnRes, short aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	if (aType == QUOTE_LV_TYPE_ALL)
	{
        QUOTELV_STOCK_POINT *pdata = aOwnRes->ownData;
		memset(aOwnRes,0,sizeof(QUOTELV_OWNALL_RES));
        aOwnRes->ownData = pdata;
	}
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	int m = 0;
	aOwnRes->fdcount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for (; i<aOwnRes->fdcount; i++)
	{
		aOwnRes->fd[i] = BytesToShort(aSrc,nPos);
		nPos += 2;
	}
	
	aOwnRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
    if(aType == QUOTE_LV_TYPE_ALL)
    {
        if(aOwnRes->nCount > aOwnRes->nMaxCount)
        {
            aOwnRes->nMaxCount = aOwnRes->nCount;
            Tools_Free(&aOwnRes->ownData);
            aOwnRes->ownData = (QUOTELV_STOCK_POINT*)Tools_Malloc(sizeof(QUOTELV_STOCK_POINT)*aOwnRes->nMaxCount);
        }
    }
	
	if(aType == QUOTE_LV_TYPE_ALL)			//如果是全包就是返回的总量
	{
		
		aOwnRes->nTotalCount = aOwnRes->nCount;
		
		for(i=0; i<aOwnRes->nCount; i++)
		{
			for (j=0; j<aOwnRes->fdcount; j++)
			{
				QuoteDataLV_ParseStockPoint(aSrc,&aOwnRes->ownData[i],aOwnRes->fd[j],&nPos);
			}
		}
	}
	else
	{
		QUOTELV_STOCK_POINT		tPoint;				//临时存储变量
		int len = sizeof(QUOTELV_STOCK_POINT);
		
		for(i=0; i<aOwnRes->nCount; i++)
		{
			
			memset(&tPoint,0,len);
			
			for (j=0; j<aOwnRes->fdcount; j++)
			{
				QuoteDataLV_ParseStockPoint(aSrc,&tPoint,aOwnRes->fd[j],&nPos);
			}
			
			for (m=0; m<aOwnRes->nTotalCount; m++)
			{
				if (strcmp(tPoint.code,aOwnRes->ownData[m].codeinfo.code) == 0)
				{
					int n = sizeof(CODELV_INFO);
					void *pd = &aOwnRes->ownData[m];
					void *ps = &tPoint;
					memcpy(pd+n,ps+n,len-n);
					break;
				}
			}
			
		}
	}
	
	
}

void QuoteDataLV_ParseRankingData(char *aSrc, QUOTELV_RANKING_RES *aRankingRes, short aType)
{
	if(aSrc == NULL )
	{
		return;
	}
	
	
	memset(aRankingRes,0,sizeof(QUOTELV_RANKING_RES));
	int nPos = 0;
	int i = 0;
	aRankingRes->blockId = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aRankingRes->nCount = aSrc[nPos];
	nPos += 1;
	
	int nIndex = 0;
	for(i=0; i<9; i++)
	{
		for(int j=0; j<aRankingRes->nCount; j++)
		{
			//codeinfo
			QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_CODEINFO,&nPos);
			//现价
			QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_NOW,&nPos);
			//最高价
			QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_PRECLOSE,&nPos);
			
			//类型标记
			int nType = aSrc[nPos];
			nPos+=1;
			switch (nType) {
				case 1:
				case 2:
					//幅度
					nPos+=4;
					QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_DR,&nPos);
					break;
				case 3:
					//振幅
					nPos+=4;
					QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_AMP,&nPos);
					break;
				case 4:
				case 5:
					//5分钟幅度
					nPos+=4;
					QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_5MDIFF,&nPos);
					break;
				case 6:
					//量比
					nPos+=4;
					QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_VR,&nPos);
					break;
				case 7:
				case 8:
					//委比
					nPos+=4;
					QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_WB,&nPos);
					break;
				case 9:
					//成交金额
					QuoteDataLV_ParseStockPoint(aSrc,&aRankingRes->stockData[nIndex],QUOTELV_CUSTOM_AMOUNT,&nPos);
					break;
			}
			nIndex++;
		}
	}
	
	aRankingRes->nTotalCount = nIndex;
}


//
//#define BytesToFloatEx(a,i,d) ((BytesToInt(a,i))/pow(10, d))
void QuoteDataLV_ParseMinData(char *aSrc, QUOTELV_MIN_RES *aMinRes, short aResType, short aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		//add by jason 
		int nSubID;
		nSubID = aMinRes->nSubID;
		memset(aMinRes,0,sizeof(QUOTELV_MIN_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aMinRes->codeinfo,&nPos);
		//aMinRes->fPre = (BytesToInt(aSrc,nPos)+0.0)/pow(10, aMinRes->codeinfo.decNum);//BytesToFloatEx(aSrc,nPos,aMinRes->codeinfo.decNum);//压缩的
		aMinRes->fPre = (BytesToInt(aSrc,nPos))/10000.0;//BytesToFloatEx(aSrc,nPos,aMinRes->codeinfo.decNum);//非压缩
    nPos+=4;
		aMinRes->nTotalCount = 0;
		aMinRes->nSubID = nSubID;
	}
	
	aMinRes->lTotalSum = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aMinRes->lTotalVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	
	if(aResType == RQS_LV_MIN || aResType == RQS_LV_DFTMIN)
	{
		aMinRes->nIndex = BytesToShort(aSrc,nPos);
		nPos += 2;
	}
	
	aMinRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	aMinRes->fdcount = aSrc[nPos];
	nPos += 1;
	
	for (; i<aMinRes->fdcount; i++)
	{
		aMinRes->fd[i] = aSrc[nPos];
		nPos += 1;
	}
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		QUOTELV_MIN_POINT *pMinPre;
		
		memset(&aMinRes->minData[0+aMinRes->nIndex], 0, sizeof(QUOTELV_MIN_POINT));
		pMinPre = &aMinRes->minData[0+aMinRes->nIndex];
		
		for(i=0; i<aMinRes->nCount; i++)
		{
			
      for (j=0; j<aMinRes->fdcount; j++)
      {
        //QuoteDataLV_ParseMinPoint2(aSrc,&aMinRes->minData[i+aMinRes->nIndex],aMinRes->fd[j],&nPos,aMinRes->codeinfo.decNum,pMinPre);//压缩
        QuoteDataLV_ParseMinPoint2(aSrc,&aMinRes->minData[i+aMinRes->nIndex],aMinRes->fd[j],&nPos);//非压缩
      }
      
      //pMinPre = &aMinRes->minData[i+aMinRes->nIndex];//压缩
			
      if(aMinRes->minData[i+aMinRes->nIndex].fPri==0 /*|| aMinRes->minData[i+aMinRes->nIndex].fAvgPrice==0*/)
      {
          if(i==0)
          {
              aMinRes->minData[i+aMinRes->nIndex].fPri = aMinRes->fPre;
          }
          else
          {
              aMinRes->minData[i+aMinRes->nIndex].fPri = aMinRes->minData[i+aMinRes->nIndex-1].fPri;
              aMinRes->minData[i+aMinRes->nIndex].fAvgPrice = aMinRes->minData[i+aMinRes->nIndex-1].fAvgPrice;
          }
      }
		}
		
		aMinRes->nTotalCount = aMinRes->nCount;
	}
	else
	{
		QUOTELV_MIN_POINT *pMinPre;
		QUOTELV_MIN_POINT tmpPoint;
		memset(&tmpPoint, 0, sizeof(QUOTELV_MIN_POINT));
		pMinPre = &tmpPoint;
		
		for(i=0; i<aMinRes->nCount; i++)
		{
			for (j=0; j<aMinRes->fdcount; j++)
			{
        //QuoteDataLV_ParseMinPoint2(aSrc,&aMinRes->minData[i+aMinRes->nIndex],aMinRes->fd[j],&nPos,aMinRes->codeinfo.decNum,pMinPre);//压缩
				QuoteDataLV_ParseMinPoint2(aSrc,&aMinRes->minData[i+aMinRes->nIndex],aMinRes->fd[j],&nPos);//非压缩
			}
			
			//pMinPre = &aMinRes->minData[i+aMinRes->nIndex];//压缩
			
      if(aMinRes->minData[i+aMinRes->nIndex].fPri==0 /*|| aMinRes->minData[i+aMinRes->nIndex].fAvgPrice==0*/)
      {
          if(aMinRes->nIndex==0)
          {
              aMinRes->minData[i+aMinRes->nIndex].fPri = aMinRes->fPre;
          }
          else
          {
              aMinRes->minData[i+aMinRes->nIndex].fPri = aMinRes->minData[i+aMinRes->nIndex-1].fPri;
              aMinRes->minData[i+aMinRes->nIndex].fAvgPrice = aMinRes->minData[i+aMinRes->nIndex-1].fAvgPrice;
          }
      }
		}
		
		for (i=aMinRes->nTotalCount; i<aMinRes->nIndex; i++) {
			memcpy(&aMinRes->minData[i],&aMinRes->minData[aMinRes->nTotalCount],sizeof(QUOTELV_MIN_POINT));
		}
		
		aMinRes->nTotalCount = aMinRes->nIndex + aMinRes->nCount;
	}
}

//lisz add 20110916 start
void QuoteDataLV_ParseLeve2MinData(char *aSrc, QUOTELV_MIN_RES *aMinRes, short aResType, short aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	
	int nPos = 0;
	int i = 0;
	int j = 0;
  
  CODELV_INFO codeInfo;
  
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		//memset(aMinRes,0,sizeof(QUOTELV_MIN_RES));
    
    //股票信息
		QuoteDataLV_ParseStockInfo(aSrc, &codeInfo, &nPos);
		
    //流通盘
    aMinRes->lFloatShare = BytesToLong64(aSrc, nPos);
    nPos += 8;

		aMinRes->nLeve2TotalCount = 0;
	}
	
  //字段个数
  int fdcount;
  //临时存放字段id数组
  char  fd[ITEMLV_NUM];
	fdcount = aSrc[nPos];
	nPos += 1;
	
	for (; i<fdcount; i++)
	{
		fd[i] = aSrc[nPos];
		nPos += 1;
	}
  
  int nIndex;
  int nCount;
  
  //起始位置
  nIndex = BytesToShort(aSrc,nPos);
  nPos+=2;
  
  //当前包点个数
  nCount = BytesToShort(aSrc,nPos);
  nPos+=2;

	if(aType == QUOTE_LV_TYPE_ALL)
	{
		//add by jason 
		int nSubID;
		nSubID = aMinRes->nSubID;
    //因n点信息是前一个点信息与当前传送值的和，所以在解每个点时需要把前一个点传递进解包函数。
    QUOTELV_LEVE2_MIN_POINT *pMinPre;
		memset(&aMinRes->leve2MinData[0+nIndex], 0, sizeof(QUOTELV_LEVE2_MIN_POINT));
		pMinPre = &aMinRes->leve2MinData[0+nIndex];
    
    //循环解分时点
		for(i=0; i<nCount; i++)
		{
			
			for (j=0; j<fdcount; j++)
			{
				QuoteDataLV_ParseLeve2MinPoint(aSrc,
                                       &aMinRes->leve2MinData[i+nIndex],
                                       fd[j],
                                       &nPos,
                                       pMinPre);
			}
      pMinPre = &aMinRes->leve2MinData[i+nIndex];
		}
		
		aMinRes->nLeve2TotalCount = nCount;
		aMinRes->nSubID = nSubID;
	}
	else
	{
		QUOTELV_LEVE2_MIN_POINT *pMinPre;
		memset(&aMinRes->leve2MinData[0+nIndex], 0, sizeof(QUOTELV_LEVE2_MIN_POINT));
		if (nIndex>0) {
			pMinPre = &aMinRes->leve2MinData[0+nIndex-1];
		} else {
			pMinPre = &aMinRes->leve2MinData[0];
		}
    
		for(i=0; i<nCount; i++)
		{
			for (j=0; j<fdcount; j++)
			{
				QuoteDataLV_ParseLeve2MinPoint(aSrc,
                                       &aMinRes->leve2MinData[i+nIndex],
                                       fd[j],
                                       &nPos,
                                       pMinPre);
			}
      pMinPre = &aMinRes->leve2MinData[i+nIndex];
		}
		
    //数据修正，一但数据传递过程发生跳跃，进行中间点的数据补全。
		for (i=aMinRes->nLeve2TotalCount; i<nIndex; i++) {
			memcpy(&aMinRes->leve2MinData[i],&aMinRes->leve2MinData[aMinRes->nLeve2TotalCount],sizeof(QUOTELV_LEVE2_MIN_POINT));
		}
		
		aMinRes->nLeve2TotalCount = nIndex + nCount;
	}
}
//lisz add 20110916 end



void QuoteDataLV_ParseDFTMinData(char *aSrc, QUOTELV_MIN_RES *aMinRes, short aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	
	int nPos = 0;
	int i = 0;
	int nIndex = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		//add by jason 
		int nSubID;
		nSubID = aMinRes->nSubID;
		memset(aMinRes,0,sizeof(QUOTELV_MIN_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aMinRes->codeinfo,&nPos);
		aMinRes->fPre = BytesToFloat(aSrc,nPos);
		nPos += 4;
		aMinRes->nSubID = nSubID;
	}
	else
	{
		nIndex = aMinRes->nIndex;
		nIndex = nIndex > 0 ? nIndex : 0;
	}
	
	aMinRes->lTotalSum = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aMinRes->lTotalVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	
	aMinRes->nIndex = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	aMinRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for(i=nIndex; i<aMinRes->nCount; i++)
	{

		aMinRes->minData[i].fPri = BytesToFloat(aSrc,nPos); 
		nPos += 4;	
		aMinRes->minData[i].lVol = BytesToLong64(aSrc,nPos); 
		nPos += 8;
		aMinRes->minData[i].fAvgPrice = BytesToFloat(aSrc,nPos); 
		nPos += 4;
		aMinRes->minData[i].nTotalBuyVolume = BytesToLong64(aSrc,nPos); 
		nPos += 8;	
		aMinRes->minData[i].nTotalSellVolume = BytesToLong64(aSrc,nPos); 
		nPos += 8;
		
	}
}

void QuoteDataLV_ParseKData2(char *aSrc, QUOTELV_K_RES *aKRes, short aType, int aPageCount,int aOffset,TBOOL bIsExDIVI)
{
  if(aSrc == NULL)
  {
    return;
  }
  
  int nPos = 0;
  int i = 0;
  int j = 0;
  
  if(aType == QUOTE_LV_TYPE_ALL)
  {
    memset(aKRes,0,sizeof(QUOTELV_K_RES));
    QuoteDataLV_ParseStockInfo(aSrc,&aKRes->codeinfo,&nPos);
    aKRes->nTotalCount = 0;
    aKRes->nOffset = aOffset;
    
  }
  if (bIsExDIVI) {//判断是否为除复权数据
    aKRes->exdiviType = aSrc[nPos];
    nPos += 1;
  }
  
  aKRes->kLineType = aSrc[nPos];
  nPos += 1;
  
  aKRes->fdcount = aSrc[nPos];
  nPos += 1;
  
  for (; i<aKRes->fdcount; i++)
  {
    aKRes->fd[i] = aSrc[nPos];
    nPos += 1;
  }
  
  aKRes->nCount = BytesToShort(aSrc,nPos);
  nPos += 2;
  
  if(aType == QUOTE_LV_TYPE_ALL)					//全包处理
  {
    QUOTELV_K_POINT *pKPre;
    
    memset(&aKRes->kData[0+aKRes->nOffset], 0, sizeof(QUOTELV_K_POINT));
    pKPre = &aKRes->kData[0+aKRes->nOffset];
    
    for(i =0; i<aKRes->nCount; i++)
    {
      for (j=0; j<aKRes->fdcount; j++)
      {
        QuoteDataLV_ParseKPoint(aSrc,&aKRes->kData[i+aKRes->nOffset],aKRes->fd[j],&nPos, aKRes->codeinfo.decNum, pKPre);
      }
      pKPre = &aKRes->kData[i+aKRes->nOffset];
    }
    
    aKRes->Addedcount = aSrc[nPos];
    nPos += 1;
    int maxNum = 0;
    pKPre = &aKRes->kData[0+aKRes->nOffset];
    for(i=0; i<aKRes->Addedcount; i++)
    {
      aKRes->Added[i][0] = aSrc[nPos];
      nPos += 1;
      aKRes->Added[i][1] = aSrc[nPos];
      nPos += 1;
      
      maxNum = maxNum > aKRes->Added[i][1] ? maxNum : aKRes->Added[i][1];
      
      j = aOffset - aKRes->Added[i][1];
      
      for (; j<aOffset; j++)
      {
        QuoteDataLV_ParseKPoint(aSrc,&aKRes->kData[j],aKRes->Added[i][0],&nPos,aKRes->codeinfo.decNum, pKPre);
      }
      pKPre = &aKRes->kData[i+aKRes->nOffset];
    }
    
    aKRes->nTotalCount = aKRes->nCount;
    aKRes->nMaxCount = aKRes->nTotalCount + maxNum;
    aKRes->nKStartPos = maxNum;
    
    if (aKRes->nOffset != aKRes->nKStartPos) {
      for (i=aKRes->nKStartPos; i<aKRes->nMaxCount; i++) {
        memcpy(&aKRes->kData[i],&aKRes->kData[i-aKRes->nKStartPos+aKRes->nOffset],sizeof(QUOTELV_K_POINT));
      }
      
      aKRes->nOffset = maxNum;
    }
  }
  else
  {
    char isAppend = aSrc[nPos];
    nPos += 1;
    int structLen = sizeof(QUOTELV_K_POINT);
    // 推送包节点个数
    int iPushPackPointCount = aKRes->nCount;
    
    // 异常处理
    if( iPushPackPointCount == 0)
    {
      return ;
    }
    // 新接收节点中新增加的点个数
    int iInceptPointCount = 0 ;
    
    // 创建临时K线节点数组
    QUOTELV_K_POINT *temppoints = ( QUOTELV_K_POINT* )Tools_Malloc( structLen * iPushPackPointCount );
    
    QUOTELV_K_POINT *pKPre;
    pKPre = &temppoints[0];//&aKRes->kData[aKRes->nOffset + aKRes->nTotalCount - 1];
    // 解析推送包节点
    for(i = 0 ; i < iPushPackPointCount ; i ++ )
    {
      for (j=0; j<aKRes->fdcount; j++)
      {
        QuoteDataLV_ParseKPoint(aSrc,&temppoints[i],aKRes->fd[j],&nPos,aKRes->codeinfo.decNum, pKPre);
      }
      pKPre = &temppoints[i];
      // 判断当前节点是否为新节点
      if( i == 0 && isAppend == '\1')
      {
        // 替换节点内容( 修正节点内容)
        memcpy(&aKRes->kData[aKRes->nOffset + aKRes->nTotalCount - 1],&temppoints[i], structLen);
      }
      else
      {
        iInceptPointCount++;
      }
      
      
    }
    
    // 当前屏幕K线个数最大值
    int iKPointCountMax = aPageCount;
    
    // 当前屏幕最大数
    int iCurrentCountMax = aKRes->nTotalCount + iInceptPointCount;
    
    if (iCurrentCountMax <= iKPointCountMax)
    {
      
      for (i = aKRes->nTotalCount; i < iCurrentCountMax; i++)
      {
        memcpy(&aKRes->kData[i+aKRes->nOffset],&temppoints[iPushPackPointCount - iInceptPointCount + i],structLen);
      }
      
      aKRes->nTotalCount += iInceptPointCount;
    }
    else
    {
      int offset = iCurrentCountMax - iKPointCountMax;
      memcpy(aKRes->kData, &aKRes->kData[offset], structLen*(iKPointCountMax+aKRes->nOffset-offset));
      memcpy(&aKRes->kData[iKPointCountMax+aKRes->nOffset-offset], &temppoints[iInceptPointCount-1], structLen*(iInceptPointCount));
    }
    
    Tools_Free((void**)&temppoints );
  }
  
  return;
}

void QuoteDataLV_ParseKData(char *aSrc, QUOTELV_K_RES *aKRes, short aType, int aPageCount,int aOffset,TBOOL bIsExDIVI)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		memset(aKRes,0,sizeof(QUOTELV_K_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aKRes->codeinfo,&nPos);
		aKRes->nTotalCount = 0;
		aKRes->nOffset = aOffset;
		
	}
	if (bIsExDIVI) {//判断是否为除复权数据
		aKRes->exdiviType = aSrc[nPos];
		nPos += 1;
	}
	
	aKRes->kLineType = aSrc[nPos];
	nPos += 1;

	aKRes->fdcount = aSrc[nPos];
	nPos += 1;
	
	for (; i<aKRes->fdcount; i++)
	{
		aKRes->fd[i] = aSrc[nPos];
		nPos += 1;
	}
	
	aKRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if(aType == QUOTE_LV_TYPE_ALL)					//全包处理
	{
		QUOTELV_K_POINT *pKPre;
		
		memset(&aKRes->kData[0+aKRes->nOffset], 0, sizeof(QUOTELV_K_POINT));
		pKPre = &aKRes->kData[0+aKRes->nOffset];
		
		for(i =0; i<aKRes->nCount; i++)
		{
			for (j=0; j<aKRes->fdcount; j++)
			{
				QuoteDataLV_ParseKPoint2(aSrc,&aKRes->kData[i+aKRes->nOffset],aKRes->fd[j],&nPos, aKRes->codeinfo.decNum, pKPre);
			}
			pKPre = &aKRes->kData[i+aKRes->nOffset];
		}
		
		aKRes->Addedcount = aSrc[nPos];
		nPos += 1;
		int maxNum = 0;
		pKPre = &aKRes->kData[0+aKRes->nOffset];
		for(i=0; i<aKRes->Addedcount; i++)
		{
			aKRes->Added[i][0] = aSrc[nPos];
			nPos += 1;
			aKRes->Added[i][1] = aSrc[nPos];
			nPos += 1;	

			maxNum = maxNum > aKRes->Added[i][1] ? maxNum : aKRes->Added[i][1];

			j = aOffset - aKRes->Added[i][1];

			for (; j<aOffset; j++)
			{
				QuoteDataLV_ParseKPoint2(aSrc,&aKRes->kData[j],aKRes->Added[i][0],&nPos,aKRes->codeinfo.decNum, pKPre);
			}
			pKPre = &aKRes->kData[i+aKRes->nOffset];
		}

		aKRes->nTotalCount = aKRes->nCount;
		aKRes->nMaxCount = aKRes->nTotalCount + maxNum;
		aKRes->nKStartPos = maxNum;
		
		if (aKRes->nOffset != aKRes->nKStartPos) {
			for (i=aKRes->nKStartPos; i<aKRes->nMaxCount; i++) {
				memcpy(&aKRes->kData[i],&aKRes->kData[i-aKRes->nKStartPos+aKRes->nOffset],sizeof(QUOTELV_K_POINT));
			}
			
			aKRes->nOffset = maxNum;
		}
	}else{
		char isAppend = aSrc[nPos];
		nPos += 1;
		int structLen = sizeof(QUOTELV_K_POINT);
		// 推送包节点个数
		int iPushPackPointCount = aKRes->nCount;
		
		// 异常处理
		if( iPushPackPointCount == 0)
		{
			return ;
		}
		// 新接收节点中新增加的点个数
		int iInceptPointCount = 0 ;
		
		// 创建临时K线节点数组
		QUOTELV_K_POINT *temppoints = ( QUOTELV_K_POINT* )Tools_Malloc( structLen * iPushPackPointCount );
		
		QUOTELV_K_POINT *pKPre;
		pKPre = &temppoints[0];//&aKRes->kData[aKRes->nOffset + aKRes->nTotalCount - 1];
		// 解析推送包节点
		for(i = 0 ; i < iPushPackPointCount ; i ++ )
		{
			for (j=0; j<aKRes->fdcount; j++)
			{
				QuoteDataLV_ParseKPoint2(aSrc,&temppoints[i],aKRes->fd[j],&nPos,aKRes->codeinfo.decNum, pKPre);
			}
			pKPre = &temppoints[i];
			// 判断当前节点是否为新节点
			if( i == 0 && isAppend == '\1')
			{
				// 替换节点内容( 修正节点内容)
				memcpy(&aKRes->kData[aKRes->nOffset + aKRes->nTotalCount - 1],&temppoints[i], structLen);
			}
			else
			{
				iInceptPointCount++;
			}
		}
		
		// 当前屏幕K线个数最大值
		int iKPointCountMax = aPageCount;
		
		// 当前屏幕最大数
		int iCurrentCountMax = aKRes->nTotalCount + iInceptPointCount;
		
		if (iCurrentCountMax <= iKPointCountMax)
		{
			
			for (i = aKRes->nTotalCount; i < iCurrentCountMax; i++)
			{
				memcpy(&aKRes->kData[i+aKRes->nOffset],&temppoints[iPushPackPointCount - iInceptPointCount + i],structLen);
			}
			
			aKRes->nTotalCount += iInceptPointCount;
		}
		else
		{
			int offset = iCurrentCountMax - iKPointCountMax;
      memcpy(aKRes->kData, &aKRes->kData[offset], structLen*(iKPointCountMax+aKRes->nOffset-offset));
      memcpy(&aKRes->kData[iKPointCountMax+aKRes->nOffset-offset], &temppoints[iInceptPointCount-1], structLen*(iInceptPointCount));
		}
		
		Tools_Free((void**)&temppoints );
	}
	
	return;
}


void QuoteDataLV_ParseLeve2KData(char *aSrc, QUOTELV_K_RES *aKRes, short aType, int aPageCount,int aOffset)
{
  if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	
  CODELV_INFO			codeinfo;
  int nTotalCount = 0;
  int nOffset = 0;
  int nMaxCount;
  int nKStartPos;
  
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		QuoteDataLV_ParseStockInfo(aSrc,&codeinfo,&nPos);
    nTotalCount = 0;
    //保持与k线相同的偏移
    nOffset = aKRes->nOffset;
    
//    if (!strestr(codeinfo.code, aKRes->codeinfo.code)) {
//      //不是同一支股票，放弃
//      return;
//    }
    
    //流通盘数目
    byte shareLen = aSrc[nPos];
    nPos += 1;
    //跳过结构长度
    for (int i = 0; i < shareLen; i++) {
      //流通盘
      aKRes->lFloatShare[i] = BytesToLong64(aSrc, nPos);
      nPos += 8;
      //跳过日期
      nPos += 4;
    }
	}
  
  
  //跳过Ｋ线请示类型
	nPos += 1;
  //订购字段数
  int   fdcount;
  char  fd[ITEMLV_NUM];
	fdcount = aSrc[nPos];
	nPos += 1;
	
	for (; i<fdcount; i++)
	{
		fd[i] = aSrc[nPos];
		nPos += 1;
	}
	
  //点个数
	int nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if(aType == QUOTE_LV_TYPE_ALL)					//全包处理
	{
	int nKStart = aKRes->nTotalCount-nCount+nOffset;//以最后一个数据为对齐点
	
    //解k线点数据
		for(i =0; i<nCount; i++)
		{
			for (j=0; j<fdcount; j++)
			{
				QuoteDataLV_ParseLeve2KPoint(aSrc,
                                     &aKRes->leve2KData[i+nKStart],
                                     fd[j],
                                     &nPos);
			}
		}
		
    //解补充点数据。
		int Addedcount = aSrc[nPos];
		nPos += 1;
    char Added[ITEMLV_NUM][2];
		int maxNum = 0;
		for(i=0; i<Addedcount; i++)
		{
			Added[i][0] = aSrc[nPos];
			nPos += 1;
			Added[i][1] = aSrc[nPos];
			nPos += 1;	
      
			maxNum = maxNum > Added[i][1] ? maxNum : Added[i][1];
      
			j = nKStart - Added[i][1];
      
			for (; j<nKStart; j++)
			{
				QuoteDataLV_ParseLeve2KPoint(aSrc,
                                     &aKRes->leve2KData[j],
                                     Added[i][0],
                                     &nPos);
			}
		}

    //因为对齐到了k线点，所以总个数变化
      aKRes->nEffectiveCount = aKRes->nTotalCount;
		
	}
	else
	{
		char isAppend = aSrc[nPos];
		nPos += 1;
		int structLen = sizeof(QUOTELV_LEVE2_K_POINT);
		// 推送包节点个数
		int iPushPackPointCount = nCount;
		
		// 异常处理
		if( iPushPackPointCount == 0)
		{
			return ;
		}
		// 新接收节点中新增加的点个数
		int iInceptPointCount = 0 ;
		
		// 创建临时K线节点数组
		QUOTELV_LEVE2_K_POINT *temppoints = 
        (QUOTELV_LEVE2_K_POINT*)Tools_Malloc(structLen * iPushPackPointCount);
		
		
		// 解析推送包节点
		for(i = 0 ; i < iPushPackPointCount ; i ++ )
		{
			for (j=0; j<fdcount; j++)
			{
				QuoteDataLV_ParseLeve2KPoint(aSrc,&temppoints[i],fd[j],&nPos);
			}
			
			// 判断当前节点是否为新节点
			if( i == 0 && isAppend == '\1')
			{
				// 替换节点内容( 修正节点内容)
				memcpy(&aKRes->leve2KData[aKRes->nOffset + aKRes->nEffectiveCount - 1],
               &temppoints[i], 
               structLen);
			}
			else
			{
				iInceptPointCount++;
			}
			
			
		}
		
		// 当前屏幕K线个数最大值
		int iKPointCountMax = aPageCount;
		
		// 当前屏幕最大数
		int iCurrentCountMax = aKRes->nEffectiveCount + iInceptPointCount;
		
		if (iCurrentCountMax <= iKPointCountMax)
		{
			
			for (i = aKRes->nEffectiveCount; i < iCurrentCountMax; i++)
			{
				memcpy(&aKRes->leve2KData[i+aKRes->nOffset],&temppoints[iPushPackPointCount - iInceptPointCount + i],structLen);
			}
			
			aKRes->nEffectiveCount += iInceptPointCount;
		}
		else
		{
      int offset = iCurrentCountMax - iKPointCountMax;
      memcpy(aKRes->leve2KData, &aKRes->leve2KData[offset], structLen*(iKPointCountMax+aKRes->nOffset-offset));
      memcpy(&aKRes->leve2KData[iKPointCountMax+aKRes->nOffset-offset], &temppoints[iInceptPointCount-1], structLen*(iInceptPointCount));
		}
    
		Tools_Free((void**)&temppoints );
	}
	
	return;
}

void QuoteDataLV_ParseLeve2TrancKData(char *aSrc,
                                      QUOTELV_K_RES *aKRes,
                                      short aType,
                                      int aPageCount,
                                      int aOffset)
{
  if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	
  CODELV_INFO			codeinfo;
  int nTotalCount = 0;
  int nOffset = 0;
  int nMaxCount;
  int nKStartPos;
  
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		QuoteDataLV_ParseStockInfo(aSrc,&codeinfo,&nPos);
    nTotalCount = 0;
   //保持与k线相同的偏移
    nOffset = aKRes->nOffset;
    
//    if (!strestr(codeinfo.code, aKRes->codeinfo.code)) {
//      //不是同一支股票，放弃
//      return;
//    }
    
    //流通盘数目
    byte shareLen = aSrc[nPos];
    nPos += 1;
    //跳过结构长度
    for (int i = 0; i < shareLen; i++) {
      //流通盘
      aKRes->lTrancFloatShare[i] = BytesToLong64(aSrc, nPos);
      nPos += 8;
      //跳过日期
      nPos += 4;
    }
	}
  
  
  //跳过Ｋ线请示类型
	nPos += 1;
  //订购字段数
  int   fdcount;
  char  fd[ITEMLV_NUM];
	fdcount = aSrc[nPos];
	nPos += 1;
	
	for (; i<fdcount; i++)
	{
		fd[i] = aSrc[nPos];
		nPos += 1;
	}
	
  //点个数
	int nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if(aType == QUOTE_LV_TYPE_ALL)					//全包处理
	{
    QUOTELV_LEVE2_K_TRANC_POINT *pKPre;
		
		int nKStart = aKRes->nTotalCount-nCount+nOffset;//以最后一个数据为对齐点
		memset(&aKRes->leve2TrancKData[0+nKStart], 0, sizeof(QUOTELV_LEVE2_K_TRANC_POINT));
		pKPre = &aKRes->leve2TrancKData[0+nKStart];
    
		for(i =0; i<nCount; i++)
		{
			for (j=0; j<fdcount; j++)
			{
				QuoteDataLV_ParseLeve2TrancKPoint(aSrc,
                                          &aKRes->leve2TrancKData[i+nKStart],
                                          fd[j],
                                          &nPos,
                                          pKPre);
			}
      pKPre = &aKRes->leve2TrancKData[i+nKStart];
		}
		
		int Addedcount = aSrc[nPos];
		nPos += 1;
    char Added[ITEMLV_NUM][2];
		int maxNum = 0;
    pKPre = &aKRes->leve2TrancKData[0+nKStart];
		for(i=0; i<Addedcount; i++)
		{
			Added[i][0] = aSrc[nPos];
			nPos += 1;
			Added[i][1] = aSrc[nPos];
			nPos += 1;	
      
			maxNum = maxNum > Added[i][1] ? maxNum : Added[i][1];
      
			j = nKStart - Added[i][1];
      
			for (; j<nKStart; j++)
			{
				QuoteDataLV_ParseLeve2TrancKPoint(aSrc,
                                          &aKRes->leve2TrancKData[j],
                                          Added[i][0],
                                          &nPos,
                                          pKPre);
			}
		}

    //因为对齐到了k线点，所以总个数变化
      aKRes->nTrancEffectiveCount = aKRes->nTotalCount;
		
	}
	else
	{
    char isAppend = aSrc[nPos];
		nPos += 1;
		int structLen = sizeof(QUOTELV_LEVE2_K_TRANC_POINT);
		// 推送包节点个数
		int iPushPackPointCount = nCount;
		
		// 异常处理
		if( iPushPackPointCount == 0)
		{
			return ;
		}
		// 新接收节点中新增加的点个数
		int iInceptPointCount = 0 ;
		
		// 创建临时K线节点数组
		QUOTELV_LEVE2_K_TRANC_POINT *temppoints = 
        (QUOTELV_LEVE2_K_TRANC_POINT*)Tools_Malloc(structLen * iPushPackPointCount);
		
		QUOTELV_LEVE2_K_TRANC_POINT *pKPre = temppoints;
		// 解析推送包节点
		for(i = 0 ; i < iPushPackPointCount ; i ++ )
		{
			for (j=0; j<fdcount; j++)
			{
				QuoteDataLV_ParseLeve2TrancKPoint(aSrc,
                                          &temppoints[i],
                                          fd[j],
                                          &nPos,
                                          pKPre);
			}
			pKPre = &temppoints[i];
      
			// 判断当前节点是否为新节点
			if( i == 0 && isAppend == '\1')
			{
				// 替换节点内容( 修正节点内容)
        memcpy(&aKRes->leve2TrancKData[aKRes->nOffset + aKRes->nTrancEffectiveCount - 1],
               &temppoints[i], 
               structLen);
			}
			else
			{
				iInceptPointCount++;
			}
			
			
		}
		
		
    
    // 当前屏幕K线个数最大值
		int iKPointCountMax = aPageCount;
		
		// 当前屏幕最大数
		int iCurrentCountMax = aKRes->nTrancEffectiveCount + iInceptPointCount;
		
		if (iCurrentCountMax <= iKPointCountMax)
		{

			for (i = aKRes->nTrancEffectiveCount; i < iCurrentCountMax; i++)
			{
				memcpy(&aKRes->leve2TrancKData[i+aKRes->nOffset],&temppoints[iPushPackPointCount - iInceptPointCount + i],structLen);
			}

			aKRes->nTrancEffectiveCount+=iInceptPointCount;
		}
		else
		{
      int offset = iCurrentCountMax - iKPointCountMax;
      memcpy(aKRes->leve2TrancKData, &aKRes->leve2TrancKData[offset], structLen*(iKPointCountMax+aKRes->nOffset-offset));
      memcpy(&aKRes->leve2TrancKData[iKPointCountMax+aKRes->nOffset-offset], &temppoints[iInceptPointCount-1], structLen*(iInceptPointCount));
		}
    
		Tools_Free((void**)&temppoints );
	}
	
	return;
}

void QuoteDataLV_ParseDetailData(char *aSrc, QUOTELV_DETAIL_RES *aDetailRes, short aType, int aPageCount)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		int nSubID;
		nSubID = aDetailRes->nSubID;
		memset(aDetailRes,0,sizeof(QUOTELV_DETAIL_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aDetailRes->codeinfo,&nPos);
		aDetailRes->fPre = BytesToFloat(aSrc,nPos);
		nPos += 4;
		aDetailRes->nZTotalCount = 0;
		aDetailRes->nSubID = nSubID;
	}
	
	
	aDetailRes->nZTotalCount = BytesToInt(aSrc,nPos);
	nPos += 4;
	
	
	aDetailRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if (aType == QUOTE_LV_TYPE_ALL)
	{
		for(i=0; i<aDetailRes->nCount; i++)
		{
			aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
			nPos += 4;
			aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
			nPos += 8;
			aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
			nPos += 4;
			aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
			nPos += 4;
			aDetailRes->detailData[i].wind = aSrc[nPos];
			nPos += 1;
		}
		
		aDetailRes->nTotalCount = aDetailRes->nCount;
	}
	else
	{
		// 部分包明细节点总数
		int iDetailedPointsCount =  aDetailRes->nCount;
		
		// 当前屏幕明细条数最大值
		int iCurDetailedPointCountMax = aDetailRes->nTotalCount + iDetailedPointsCount;
		
		// 当前屏幕明细条数小于当前屏幕明细条数最大值
		// 在原有记录后面直接追加新明细结点
		if( iCurDetailedPointCountMax <= aPageCount )
		{
			// 在数组后面添加新追加的明细结点
			for( int i = aDetailRes->nTotalCount ; i < iCurDetailedPointCountMax ; i ++ )
			{
				// 解析新增加节点
				aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
				nPos += 4;
				aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
				nPos += 8;
				aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
				nPos += 4;
				aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
				nPos += 4;
				aDetailRes->detailData[i].wind = aSrc[nPos];
				nPos += 1;
			}
			
			aDetailRes->nTotalCount = iCurDetailedPointCountMax;
		}
		// 当当前屏幕屏幕明细条数大于当前屏幕明细条数上限
		else
		{
			
		
			int i = 0 ;

			if (iDetailedPointsCount >= aPageCount)
			{
				i = iDetailedPointsCount - aPageCount;			//计算起始位置
				nPos += i*25;

				for(i=0; i < aPageCount; i ++ )
				{
					// 解析新增加节点
					aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
					nPos += 8;
					aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].wind = aSrc[nPos];
					nPos += 1;
					aDetailRes->detailData[i].nTradeIndex = BytesToInt(aSrc,nPos);
					nPos += 4;
				}
			}
			else
			{
				int nOffSet = iCurDetailedPointCountMax - aPageCount ;

				for( i = 0 ; i < ( aPageCount - iDetailedPointsCount ); i ++  )
				{
					memcpy( &aDetailRes->detailData[i] , &aDetailRes->detailData[nOffSet + i] , sizeof(QUOTELV_DETAIL_POINT));
				}

				// 追加最后iDetailedPointsCount结点
				for( i = ( aPageCount - iDetailedPointsCount ) ; i < aPageCount ; i ++ )
				{
					// 解析新增加节点
					aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
					nPos += 8;
					aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].wind = aSrc[nPos];
					nPos += 1;
				}
			}

			aDetailRes->nTotalCount = aPageCount;
		}
	}
}

void QuoteDataLV_ParseDetailLvData(char *aSrc, QUOTELV_DETAIL_RES *aDetailRes, short aType, int aPageCount)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		int nSubID = aDetailRes->nSubID;
		memset(aDetailRes,0,sizeof(QUOTELV_DETAIL_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aDetailRes->codeinfo,&nPos);
		aDetailRes->fPre = BytesToFloat(aSrc,nPos);
		nPos += 4;
		aDetailRes->nZTotalCount = 0;
		aDetailRes->nSubID = nSubID;
	}
	
	
	aDetailRes->nZTotalCount = BytesToInt(aSrc,nPos);
	nPos += 4;
	
	
	aDetailRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if (aType == QUOTE_LV_TYPE_ALL)
	{
		for(i=0; i<aDetailRes->nCount; i++)
		{
			aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
			nPos += 4;
			aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
			nPos += 8;
			aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
			nPos += 4;
			aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
			nPos += 4;
			aDetailRes->detailData[i].wind = aSrc[nPos];
			nPos += 1;
			aDetailRes->detailData[i].nTradeIndex = BytesToInt(aSrc,nPos);
			nPos += 4;
		}
		
		aDetailRes->nTotalCount = aDetailRes->nCount;
	}
	else
	{
		// 部分包明细节点总数
		int iDetailedPointsCount =  aDetailRes->nCount;
		
		// 当前屏幕明细条数最大值
		int iCurDetailedPointCountMax = aDetailRes->nTotalCount + iDetailedPointsCount;
		
		// 当前屏幕明细条数小于当前屏幕明细条数最大值
		// 在原有记录后面直接追加新明细结点
		if( iCurDetailedPointCountMax <= aPageCount )
		{
			// 在数组后面添加新追加的明细结点
			for( int i = aDetailRes->nTotalCount ; i < iCurDetailedPointCountMax ; i ++ )
			{
				// 解析新增加节点
				aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
				nPos += 4;
				aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
				nPos += 8;
				aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
				nPos += 4;
				aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
				nPos += 4;
				aDetailRes->detailData[i].wind = aSrc[nPos];
				nPos += 1;
				aDetailRes->detailData[i].nTradeIndex = BytesToInt(aSrc,nPos);
				nPos += 4;
			}
			
			aDetailRes->nTotalCount = iCurDetailedPointCountMax;
		}
		// 当当前屏幕屏幕明细条数大于当前屏幕明细条数上限
		else
		{
			int i = 0 ;

			if (iDetailedPointsCount >= aPageCount)
			{
				i = iDetailedPointsCount - aPageCount;			//计算起始位置
				nPos += i*25;

				for(i=0; i < aPageCount; i ++ )
				{
					// 解析新增加节点
					aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
					nPos += 8;
					aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].wind = aSrc[nPos];
					nPos += 1;
					aDetailRes->detailData[i].nTradeIndex = BytesToInt(aSrc,nPos);
					nPos += 4;
				}
			}
			else
			{
				int nOffSet = iCurDetailedPointCountMax - aPageCount ;
				// ( iDetailedPointsCountMax - iDetailedPointsCount )结点
				for( i = 0 ; i < ( aPageCount - iDetailedPointsCount ); i ++  )
				{
					memcpy( &aDetailRes->detailData[i] , &aDetailRes->detailData[nOffSet + i] ,  sizeof(QUOTELV_DETAIL_POINT));
				}

				// 追加最后iDetailedPointsCount结点
				for( i = ( aPageCount - iDetailedPointsCount ) ; i < aPageCount ; i ++ )
				{
					// 解析新增加节点
					aDetailRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
					nPos += 8;
					aDetailRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].nNum = BytesToInt(aSrc,nPos);
					nPos += 4;
					aDetailRes->detailData[i].wind = aSrc[nPos];
					nPos += 1;
					aDetailRes->detailData[i].nTradeIndex = BytesToInt(aSrc,nPos);
					nPos += 4;
				}

			}
			
			aDetailRes->nTotalCount = aPageCount;

		}
	}
}

void QuoteDataLV_ParseBlockData(char *aSrc, QUOTELV_BLOCK_RES *aBlockRes)
{
	if(aSrc == NULL )
	{
		return;
	}
	
	
	memset(aBlockRes,0,sizeof(QUOTELV_BLOCK_RES));
	int nPos = 0;
	int i = 0;
	int j = 0;
	aBlockRes->blockid = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aBlockRes->nZTotalCount = BytesToInt(aSrc,nPos);
	nPos += 4;
	aBlockRes->fdcount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for (; i<aBlockRes->fdcount; i++)
	{
		aBlockRes->fd[i] = BytesToShort(aSrc,nPos);
		nPos += 2;
	}
	
	aBlockRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;

	for(i=0; i<aBlockRes->nCount; i++)
	{

		for (j=0; j<aBlockRes->fdcount; j++)
		{
			QuoteDataLV_ParseStockPoint(aSrc,&aBlockRes->blockData[i],aBlockRes->fd[j],&nPos);
		}

	}

	aBlockRes->nTotalCount = aBlockRes->nCount;
}

void QuoteDataLV_ParseBlockIndexData(char *aSrc, QUOTELV_BLOCK_RES *aBlockRes)
{
	if(aSrc == NULL )
	{
		return;
	}


	memset(aBlockRes,0,sizeof(QUOTELV_BLOCK_RES));
	int nPos = 0;
	int i = 0;
	int j = 0;

	aBlockRes->nZTotalCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	aBlockRes->fdcount = BytesToShort(aSrc,nPos);
	nPos += 2;

	for (; i<aBlockRes->fdcount; i++)
	{
		aBlockRes->fd[i] = BytesToShort(aSrc,nPos);
		nPos += 2;
	}

	aBlockRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
    

	for(i=0; i<aBlockRes->nCount; i++)
	{

		for (j=0; j<aBlockRes->fdcount; j++)
		{
			QuoteDataLV_ParseStockPoint(aSrc,&aBlockRes->blockData[i],aBlockRes->fd[j],&nPos);
		}
		
	}
	
	aBlockRes->nTotalCount = aBlockRes->nCount;
}

void QuoteDataLV_ParseIndexData(char *aSrc, QUOTELV_INDEX_RES *aIndexRes, int aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	if (aType == QUOTE_LV_TYPE_ALL)
	{
		memset(aIndexRes,0,sizeof(QUOTELV_INDEX_RES));
	}
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	int m = 0;
	aIndexRes->fdcount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for (; i<aIndexRes->fdcount; i++)
	{
		aIndexRes->fd[i] = BytesToShort(aSrc,nPos);
		nPos += 2;
	}
	
	aIndexRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if(aType == QUOTE_LV_TYPE_ALL)			//如果是全包就是返回的总量
	{
		
		aIndexRes->nTotalCount = aIndexRes->nCount;
		
		for(i=0; i<aIndexRes->nCount; i++)
		{
			for (j=0; j<aIndexRes->fdcount; j++)
			{
				QuoteDataLV_ParseStockPoint(aSrc,&aIndexRes->indexData[i],aIndexRes->fd[j],&nPos);
			}
		}
	}
	else
	{
		QUOTELV_STOCK_POINT		tPoint;				//临时存储变量
		int len = sizeof(QUOTELV_STOCK_POINT);
		
		for(i=0; i<aIndexRes->nCount; i++)
		{
			
			memset(&tPoint,0,len);
			
			for (j=0; j<aIndexRes->fdcount; j++)
			{
				QuoteDataLV_ParseStockPoint(aSrc,&tPoint,aIndexRes->fd[j],&nPos);
			}
			
			for (m=0; m<aIndexRes->nTotalCount; m++)
			{
				if (strcmp(tPoint.code,aIndexRes->indexData[m].codeinfo.code) == 0)
				{
					int n = sizeof(CODELV_INFO);
					void *pd = &aIndexRes->indexData[m];
					void *ps = &tPoint;
					memcpy(pd+n,ps+n,len-n);
					//memcpy(&aIndexRes->indexData[m],&tPoint,len);
					break;
				}
			}
			
		}
	}
	
	
}

void QuoteDataLV_ParseIndividData(char *aSrc, QUOTELV_INDIVID_RES *aIndividRes, short aType, int aPageCount)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	int j = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		memset(aIndividRes,0,sizeof(QUOTELV_INDIVID_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aIndividRes->codeinfo,&nPos);
		aIndividRes->fPre = BytesToFloat(aSrc,nPos);
		nPos += 4;
		aIndividRes->nTotalCount = 0;
	}
	
	aIndividRes->nIndex = BytesToInt(aSrc,nPos);
	nPos += 4;
	
	
	aIndividRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	
	
	if (aType == QUOTE_LV_TYPE_ALL)
	{
		for(i=0; i<j+aIndividRes->nCount; i++)
		{
			aIndividRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
			nPos += 4;
			aIndividRes->detailData[i].lVol = BytesToInt(aSrc,nPos);
			nPos += 4;
			aIndividRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
			nPos += 4;
			aIndividRes->detailData[i].wind = aSrc[nPos];
			nPos += 1;
		}
		
		aIndividRes->nTotalCount = aIndividRes->nCount;
	}
	else
	{
		// 部分包明细节点总数
		int iDetailedPointsCount =  aIndividRes->nCount;
		
		// 当前屏幕明细条数最大值
		int iCurDetailedPointCountMax = aIndividRes->nTotalCount + iDetailedPointsCount;
		
		// 当前屏幕明细条数小于当前屏幕明细条数最大值
		// 在原有记录后面直接追加新明细结点
		if( iCurDetailedPointCountMax <= aPageCount )
		{
			// 在数组后面添加新追加的明细结点
			for( int i = aIndividRes->nTotalCount ; i < iCurDetailedPointCountMax ; i ++ )
			{
				// 解析新增加节点
				aIndividRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
				nPos += 4;
				aIndividRes->detailData[i].lVol = BytesToInt(aSrc,nPos);
				nPos += 4;
				aIndividRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
				nPos += 4;
				aIndividRes->detailData[i].wind = aSrc[nPos];
				nPos += 1;
			}
			
			aIndividRes->nTotalCount = iCurDetailedPointCountMax;
		}
		// 当当前屏幕屏幕明细条数大于当前屏幕明细条数上限
		else
		{
			int i = 0 ;

			if( iDetailedPointsCount >= aPageCount)				//推送数据已经超过一屏
			{
				i = iDetailedPointsCount - aPageCount;			//计算起始位置
				nPos += i*13;
				
				for(i = 0; i < aPageCount; i ++ )
				{
					// 解析新增加节点
					aIndividRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aIndividRes->detailData[i].lVol = BytesToInt(aSrc,nPos);
					nPos += 4;
					aIndividRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
					aIndividRes->detailData[i].wind = aSrc[nPos];
					nPos += 1;
				}
			}
			else
			{
				

				int nOffset = iCurDetailedPointCountMax - aPageCount;

				for( i = 0 ; i < ( aPageCount - iDetailedPointsCount ); i ++  )
				{
					memcpy( &aIndividRes->detailData[i] , &aIndividRes->detailData[nOffset + i] , sizeof( QUOTELV_DETAIL_POINT ));
				}

				// 追加最后iDetailedPointsCount结点
				for( i = ( aPageCount - iDetailedPointsCount ) ; i < aPageCount ; i ++ )
				{
					// 解析新增加节点
					aIndividRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aIndividRes->detailData[i].lVol = BytesToInt(aSrc,nPos);
					nPos += 4;
					aIndividRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
					aIndividRes->detailData[i].wind = aSrc[nPos];
					nPos += 1;
				}
			}

			aIndividRes->nTotalCount = aPageCount;	
		}
	}

}

void QuoteDataLV_ParseIndividTimeData(char *aSrc, QUOTELV_INDIVID_TIME_RES *aIndividTimeRes, short aType)
{
	if(aSrc == NULL || aIndividTimeRes == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		memset(aIndividTimeRes,0,sizeof(QUOTELV_INDIVID_TIME_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aIndividTimeRes->codeinfo,&nPos);
		aIndividTimeRes->fPre = BytesToFloat(aSrc,nPos);
		nPos += 4;
	}
	
	
	aIndividTimeRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for (; i<aIndividTimeRes->nCount; i++)
	{
		memcpy(&aIndividTimeRes->detailData[i],aSrc+nPos,sizeof(QUOTELV_DETAIL_POINT));
		nPos += sizeof(QUOTELV_DETAIL_POINT);
	}
	
}

void QuoteDataLV_ParseTrustData(char *aSrc, QUOTELV_TRUST_RES *aTrustRes, short aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		memset(aTrustRes,0,sizeof(QUOTELV_TRUST_RES));
		QuoteDataLV_ParseStockInfo(aSrc,&aTrustRes->codeinfo,&nPos);
		aTrustRes->fPre = BytesToFloat(aSrc,nPos);
		nPos += 4;
	}
	
	aTrustRes->fBidPri = BytesToFloat(aSrc,nPos);
	nPos += 4;
	
	aTrustRes->lBidVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	
	aTrustRes->nBidCount = aSrc[nPos];
	nPos += 1;
	
	for (; i<aTrustRes->nBidCount; i++)
	{
		aTrustRes->bidData[i] = BytesToInt(aSrc,nPos);
		nPos += 4;
	}
	
	aTrustRes->fAskPri = BytesToFloat(aSrc,nPos);
	nPos += 4;
	
	aTrustRes->lAskVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	
	aTrustRes->nAskCount = aSrc[nPos];
	nPos += 1;
	
	for (i=0; i<aTrustRes->nAskCount; i++)
	{
		aTrustRes->askData[i] = BytesToInt(aSrc,nPos);
		nPos += 4;
	}
	
}

void QuoteDataLV_ParseCancelTrustData(char *aSrc, QUOTELV_CANCELTRUST_RES *aTrustCancelRes, short aType, int aPageCount)
{

	if(aSrc == NULL)
	{
		return;
	}

	int nPos = 0;
	int i = 0;

	aTrustCancelRes->Type = aSrc[nPos];
	nPos += 1;

	if(aType == QUOTE_LV_TYPE_ALL)
	{
		memset(aTrustCancelRes,0,sizeof(QUOTELV_CANCELTRUST_RES));
		QuoteDataLV_ParseStockInfo(aSrc+nPos,&aTrustCancelRes->codeinfo,&nPos);
		aTrustCancelRes->fPre = BytesToFloat(aSrc,nPos);
		nPos += 4;
		aTrustCancelRes->nZTotalCount = BytesToInt(aSrc,nPos);
		nPos += 4;
	}

	aTrustCancelRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;

	if (aType == QUOTE_LV_TYPE_ALL)
	{
		for(i=0; i<aTrustCancelRes->nCount; i++)
		{
			aTrustCancelRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
			nPos += 4;
			aTrustCancelRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
			nPos += 8;
			aTrustCancelRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
			nPos += 4;
		}

		aTrustCancelRes->nTotalCount = aTrustCancelRes->nCount;
	}
	else
	{
		// 部分包明细节点总数
		int iDetailedPointsCount =  aTrustCancelRes->nCount;

		// 当前屏幕明细条数最大值
		int iCurDetailedPointCountMax = aTrustCancelRes->nTotalCount + iDetailedPointsCount;

		// 当前屏幕明细条数小于当前屏幕明细条数最大值
		// 在原有记录后面直接追加新明细结点
		if( iCurDetailedPointCountMax <= aPageCount )
		{
			// 在数组后面添加新追加的明细结点
			for( int i = aTrustCancelRes->nTotalCount ; i < iCurDetailedPointCountMax ; i ++ )
			{
				// 解析新增加节点
				aTrustCancelRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
				nPos += 4;
				aTrustCancelRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
				nPos += 8;
				aTrustCancelRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
				nPos += 4;
			}

			aTrustCancelRes->nTotalCount = iCurDetailedPointCountMax;
		}
		// 当当前屏幕屏幕明细条数大于当前屏幕明细条数上限
		else
		{


			int i = 0 ;

			if (iDetailedPointsCount >= aPageCount)
			{
				i = iDetailedPointsCount - aPageCount;			//计算起始位置
				nPos += i*16;

				for(i=0; i < aPageCount; i ++ )
				{
					// 解析新增加节点
					aTrustCancelRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aTrustCancelRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
					nPos += 8;
					aTrustCancelRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
				}
			}
			else
			{
				int nOffSet = iCurDetailedPointCountMax - aPageCount ;

				for( i = 0 ; i < ( aPageCount - iDetailedPointsCount ); i ++  )
				{
					memcpy( &aTrustCancelRes->detailData[i] , &aTrustCancelRes->detailData[nOffSet + i] , sizeof(QUOTELV_DETAIL_POINT));
				}

				// 追加最后iDetailedPointsCount结点
				for( i = ( aPageCount - iDetailedPointsCount ) ; i < aPageCount ; i ++ )
				{
					// 解析新增加节点
					aTrustCancelRes->detailData[i].fPri = BytesToFloat(aSrc,nPos);
					nPos += 4;
					aTrustCancelRes->detailData[i].lVol = BytesToLong64(aSrc,nPos);
					nPos += 8;
					aTrustCancelRes->detailData[i].nDate = BytesToInt(aSrc,nPos);
					nPos += 4;
				}
			}

			aTrustCancelRes->nTotalCount = aPageCount;
		}
	}
}

void QuoteDataLV_ParseStockInfoData(char *aSrc, QUOTELV_STOCKINFO_RES *aInfoRes, int aType)
{
	if(aSrc == NULL)
	{
		return;
	}
	
	int nPos = 0;
	int i = 0;
	
	if(aType == QUOTE_LV_TYPE_ALL)
	{
		for (; i<aInfoRes->nTotalCount; i++)			//释放所有的内存
		{
			Tools_Free((void **) &aInfoRes->infoData[i].pTitle);
			Tools_Free((void **) &aInfoRes->infoData[i].pUrl);
			Tools_Free((void **) &aInfoRes->infoData[i].pDate);
		}
		
		memset(aInfoRes,0,sizeof(QUOTELV_STOCKINFO_RES));
		aInfoRes->nTotalCount = 0;
	}
	
	memcpy(aInfoRes->StockCode,aSrc,6);
	nPos += 6;
	
	aInfoRes->MarketId = aSrc[nPos];
	nPos += 1;
	
	aInfoRes->Type = aSrc[nPos];
	nPos += 1;
	
	aInfoRes->lNewTime = BytesToLong64(aSrc,nPos);
	nPos += 8;
	
	aInfoRes->nLen = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	char *p = aSrc + nPos;
	char *p1 = NULL;
	
	while((p1 = strstr(p,"<stockinfo>")) != NULL)
	{
		QuoteDataLV_ParseInfoPoint(p1,&aInfoRes->infoData[aInfoRes->nTotalCount]);
		p += p1 - p + 11;
		aInfoRes->nTotalCount++;
	}
}

void QuoteDataLV_ParseIndividVolData(char *aSrc, QUOTELV_INDIVID_VOL_RES *aVolRes, int aType)
{
	if(aSrc == NULL)
	{
		return;
	}

	int nPos = 0;

	if(aType == QUOTE_LV_TYPE_ALL)
	{
		QuoteDataLV_ParseStockInfo(aSrc,&aVolRes->codeinfo,&nPos);
	}
	else
	{
		memcpy(aVolRes->codeinfo.code, aSrc, 6);
		nPos += 6;
		//市场
		aVolRes->codeinfo.market = aSrc[nPos];
		nPos += 1;
	}
	
	aVolRes->sBuyVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aVolRes->mBuyVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aVolRes->lBuyVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aVolRes->gBuyVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aVolRes->sSellVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aVolRes->mSellVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aVolRes->lSellVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	aVolRes->gSellVol = BytesToLong64(aSrc,nPos);
	nPos += 8;
	
	
}

void QuoteDataLV_ParseSelStockData(char *aSrc, QUOTELV_SEL_STOCK_RES *aSelRes)
{
	if(aSrc == NULL )
	{
		return;
	}
	
	
	memset(aSelRes,0,sizeof(QUOTELV_SEL_STOCK_RES));
	int nPos = 0;
	int i = 0;
	int j = 0;
	
	
	aSelRes->fdcount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	for (; i<aSelRes->fdcount; i++)
	{
		aSelRes->fd[i] = BytesToShort(aSrc,nPos);
		nPos += 2;
	}
	
	aSelRes->nCount = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	
	for(i=0; i<aSelRes->nCount; i++)
	{
		
		for (j=0; j<aSelRes->fdcount; j++)
		{
			QuoteDataLV_ParseStockPoint(aSrc,&aSelRes->stockData[i],aSelRes->fd[j],&nPos);
		}
		
	}
	
	aSelRes->nTotalCount = aSelRes->nCount;
}

void QuoteDataLV_ParseSelDirListData(char *aSrc, QUOTELV_SEL_DIRLIST_RES *aSelListRes)
{
	if(aSrc == NULL )
	{
		return;
	}


	memset(aSelListRes,0,sizeof(QUOTELV_SEL_DIRLIST_RES));
	int nPos = 0;
	int i = 0;
	


	aSelListRes->nParentdirid = BytesToShort(aSrc,nPos);
	nPos += 2;

	aSelListRes->nTotalCount = BytesToShort(aSrc,nPos);
	nPos += 2;


	for(i=0; i<aSelListRes->nTotalCount; i++)
	{
		aSelListRes->DirList[i].dirid = BytesToShort(aSrc,nPos);
		nPos += 2;
		memcpy(aSelListRes->DirList[i].pDirName,aSrc+nPos,30);
		nPos += 30;
		
		aSelListRes->DirList[i].LeafOrNot = aSrc[nPos];
		nPos += 1;
	}

}

void QuoteDataLV_ParseSelDirListAllData(char *aSrc, QUOTELV_SEL_DIRLIST_RES_ALL *aSelListRes)
{
	if(aSrc == NULL )
	{
		return;
	}
	
	
	memset(aSelListRes,0,sizeof(QUOTELV_SEL_DIRLIST_RES_ALL));
	int nPos = 0;
	int i = 0;
	
	
	
	//aSelListRes->nParentdirid = BytesToShort(aSrc,nPos);
	//					nPos += 2;
	//返回条数
	int nCount = BytesToShort(aSrc,nPos);
	aSelListRes->nDirCount = 0;//BytesToShort(aSrc,nPos);
	nPos += 2;
	
	
	int nParentIndex;
	nParentIndex = 0;
	int j = 0;
	for(i=0; i<nCount; i++)
	{
		
		unsigned short rid = BytesToShort(aSrc,nPos+32);
		if (rid == 0) {//一级目录
			nParentIndex = aSelListRes->nDirCount;
			
			aSelListRes->ParentList[nParentIndex].nDirID = BytesToShort(aSrc,nPos);
			nPos += 2;
			memcpy(aSelListRes->ParentList[nParentIndex].pParentName,aSrc+nPos,30);
			nPos += 30;
		//	printf("\n %d    %s",aSelListRes->ParentList[nParentIndex].nDirID,aSelListRes->ParentList[nParentIndex].pParentName);
			aSelListRes->ParentList[nParentIndex].nParentdirid = BytesToShort(aSrc,nPos);
			nPos += 2;
			aSelListRes->ParentList[nParentIndex].LeafOrNot = aSrc[nPos];
			nPos += 1;	
			nParentIndex += 1;
			aSelListRes->nDirCount = nParentIndex;
		}else {//子目录
			
			for(j=0; j<aSelListRes->nDirCount; j++)
			{
				if (rid == aSelListRes->ParentList[j].nDirID) {
					nParentIndex = aSelListRes->ParentList[j].nTotalCount;
					
					aSelListRes->ParentList[j].ChildList[nParentIndex].dirid = BytesToShort(aSrc,nPos);
					nPos += 2;
					memcpy(aSelListRes->ParentList[j].ChildList[nParentIndex].pDirName,aSrc+nPos,30);
					nPos += 30;
					aSelListRes->ParentList[j].ChildList[nParentIndex].nParentdirid = BytesToShort(aSrc,nPos);
					nPos += 2;
					
					//printf("\n %d    %d    %s",aSelListRes->ParentList[j].ChildList[nParentIndex].nParentdirid,aSelListRes->ParentList[j].ChildList[nParentIndex].dirid,aSelListRes->ParentList[j].ChildList[nParentIndex].pDirName);
					
					aSelListRes->ParentList[j].ChildList[nParentIndex].LeafOrNot = aSrc[nPos];
					nPos += 1;	
					nParentIndex += 1;
					aSelListRes->ParentList[j].nTotalCount = nParentIndex;
				}
			}
		}
		
	}
}

void QuoteDataLV_ParseBoardListAllData(char *aSrc, QUOTELV_SEL_BOARDLIST_ALL_RES *aSelListRes)
{
	if(aSrc == NULL )
	{
		return;
	}
	
	
	memset(aSelListRes,0,sizeof(QUOTELV_SEL_BOARDLIST_ALL_RES));
	int nPos = 0;
	int i = 0;
	
	
	
	aSelListRes->nItemCounts = BytesToShort(aSrc,nPos);
	nPos += 2;
	
	if (aSelListRes->pBoardListPoints) {
		Tools_Free((void **)&aSelListRes->pBoardListPoints);
	}
	aSelListRes->pBoardListPoints = (QUOTELV_SEL_BOARDLIST_POINT*)Tools_Malloc(sizeof(QUOTELV_SEL_BOARDLIST_POINT) * aSelListRes->nItemCounts);

	
	
	for(i=0; i<aSelListRes->nItemCounts; i++)
	{
		aSelListRes->pBoardListPoints[i].lID = BytesToLong64(aSrc,nPos);
		nPos += 8;
		memcpy(aSelListRes->pBoardListPoints[i].pName,aSrc+nPos,30);
		nPos += 30;
		aSelListRes->pBoardListPoints[i].pType = aSrc[nPos];
		nPos += 1;
	}
}

void QuoteDataLV_ParseFundListData(char *aSrc, QUOTELV_FUND_RES *aFundRes)
{
	//先清除数据，后判断
	QuoteDataLV_ReleaseFundListData(aFundRes);
	
    if (aSrc==NULL || strlen(aSrc)<=0) {
        return;
    }
	XML_NODE* pXmlData = XmlTools_Encrypt(&aSrc);
	
	int nRangeCol = -1;
	char* option;
	
	
	option = XmlTools_GetOptionValue(pXmlData->pOption, "pagecount");
	
	if (option)
	{
		aFundRes->Page.nPageCount = atoi(option);
	}else {
		//错误的结果
		XmlTools_Free(pXmlData);
		return;
	}

	
	option = XmlTools_GetOptionValue(pXmlData->pOption, "size");
	
	if (option)
	{
		aFundRes->Page.nRowCount = atoi(option);
	}
	
	option = XmlTools_GetOptionValue(pXmlData->pOption, "curindex");
	
	if (option)
	{
		aFundRes->Page.nCurPage = atoi(option);
	}
	
	option = XmlTools_GetOptionValue(pXmlData->pOption, "refresh");
	if (option)
	{
		aFundRes->Page.nRef = atoi(option);
	}
	
	option = XmlTools_GetOptionValue(pXmlData->pOption, "prevpage");
	
	if (option)
	{
		aFundRes->Page.pPrePageUrl = (char *) Tools_Malloc(strlen(option)+1);
		strcpy(aFundRes->Page.pPrePageUrl, option);
	}
	
	option = XmlTools_GetOptionValue(pXmlData->pOption, "nextpage");
	
	if (option)
	{
		aFundRes->Page.pNextPageUrl = (char *) Tools_Malloc(strlen(option)+1);
		strcpy(aFundRes->Page.pNextPageUrl, option);
	}
	
	//parser tab "table"
	XML_NODE* tableNode = XmlTools_GetLeafNodeChild(pXmlData, "table");
	
	option = XmlTools_GetOptionValue(tableNode->pOption, "bgcolor");
	
	if (option)
	{
		aFundRes->Table.nBgColor = ColorTools_HexToColor(option);
	}
	
	option = XmlTools_GetOptionValue(tableNode->pOption, "selcolor");
	
	if (option)
	{
		aFundRes->Table.nSelColor = ColorTools_HexToColor(option);
	}
	
	option = XmlTools_GetOptionValue(tableNode->pOption, "border");
	
	if (option)
	{
		aFundRes->Table.nBorColor = atoi(option);
	}
	
	
	
	// 添加列数据
	XML_NODE* column = XmlTools_GetLeafNodeChild(tableNode, "rowtitle");
	
	//计算列的数量
	XML_NODE* col = XmlTools_GetLeafNodeChild(column, "col");
	aFundRes->Page.nColCount = 0;
	
	while(col)
	{
		aFundRes->Page.nColCount++;
		col = XmlTools_GetLeafNodeNext(col, "col");
	}
	
	//申请列空间
	aFundRes->pColPro = (QUOTELV_FUND_COL *) Tools_Malloc(sizeof(QUOTELV_FUND_COL) * aFundRes->Page.nColCount);
	col = XmlTools_GetLeafNodeChild(column, "col");
	int colCount = 0;
	
	while(col)
	{
		
		QUOTELV_FUND_COL *pCol = &aFundRes->pColPro[colCount];
		option = XmlTools_GetOptionValue(col->pOption, "txtcolor");
		
		if (option)
		{
			pCol->nTextColor = ColorTools_HexToColor(option);
		}
		
		option = XmlTools_GetOptionValue(col->pOption, "align");
		
		if (option)
		{
			pCol->nAlign = atoi(option);
		}
		
		char* text = XmlTools_GetLeafText(col);
		int Len = strlen(text);
		
		if (text)
		{
			pCol->pText = (char *) Tools_Malloc(Len+1);
			memcpy(pCol->pText,text,strlen(text));
		}
		
		
		if (nRangeCol < 0 && aFundRes->pRangTag && strcmp(text, aFundRes->pRangTag) == 0)
		{
			nRangeCol = colCount;
		}
		
		col = XmlTools_GetLeafNodeNext(col, "col");
		colCount++;
	}
	
	// 添加行数据
	aFundRes->pRowPro = (QUOTELV_FUND_ROW *)Tools_Malloc(sizeof(QUOTELV_FUND_ROW)*aFundRes->Page.nRowCount);
	XML_NODE* row = XmlTools_GetLeafNodeChild(tableNode, "row");
	int rowCount = 0;
	
	while (row)
	{
		if (rowCount >= aFundRes->Page.nRowCount) {
			break;
		}
		
		QUOTELV_FUND_ROW *oneRow = &aFundRes->pRowPro[rowCount];
		oneRow->pCol = (QUOTELV_FUND_COL*)Tools_Malloc(sizeof(QUOTELV_FUND_COL)*aFundRes->Page.nColCount);
		
		option = XmlTools_GetOptionValue(row->pOption, "bgcolor");
		
		if (option)
		{
			oneRow->nBgColor = ColorTools_HexToColor(option);
		}
		
		option = XmlTools_GetOptionValue(row->pOption, "action");
		
		if (option)
		{
			int Len = strlen(option);
			oneRow->pAction = (char *)Tools_Malloc(Len+1);
			memcpy(oneRow->pAction,option,Len);
		}
		
		
		int colCount = 0;
		XML_NODE* col = XmlTools_GetLeafNodeChild(row, "col");
		
		while (col)
		{
			char* text = XmlTools_GetLeafText(col);
			int Len = strlen(text);
			
			if (text)
			{
				oneRow->pCol[colCount].pText = (char *) Tools_Malloc(Len+1);
				memcpy(oneRow->pCol[colCount].pText,text,Len);
			}
			
			option = XmlTools_GetOptionValue(col->pOption, "txtcolor");
			
			if (option)
			{
				oneRow->pCol[colCount].nTextColor = ColorTools_HexToColor(option);
			}
			
			//暂时没有解析对其方式
			
			option = XmlTools_GetOptionValue(col->pOption, "align");
			
			if (option)
			{
				oneRow->pCol[colCount].nAlign = atoi(option);
			}
			
			if (colCount == nRangeCol)
			{
				
				if (*text == '-')
				{
					oneRow->pCol[colCount].nTextColor = 0x00AA00;
					
				}
				else
				{
					oneRow->pCol[colCount].nTextColor = 0xAA0000;
					
				}
				
			}
			
			col = XmlTools_GetLeafNodeNext(col, "col");
			colCount++;
		}
		
		row = XmlTools_GetLeafNodeNext(row, "row");
		rowCount++;
	}
	
	aFundRes->Page.nRowCount = rowCount;
	
	XmlTools_Free(pXmlData);
	
}

void QuoteDataLV_ReleaseFundListData(QUOTELV_FUND_RES *aFundRes)
{
	int i = 0;
	int j = 0;
	
	//释放列内存
	for(i=0; i<aFundRes->Page.nColCount; i++)
	{
		Tools_Free((void **) &aFundRes->pColPro[i].pText);
	}
	
	if (aFundRes->pColPro) {
		Tools_Free((void **) &aFundRes->pColPro);
	}
	
	
	//释放行内存
	for(i=0; i<aFundRes->Page.nRowCount; i++)
	{
		Tools_Free((void **) &aFundRes->pRowPro[i].pAction);
		
		for(j=0; j<aFundRes->Page.nColCount; j++)
		{
			Tools_Free((void **) &aFundRes->pRowPro[i].pCol[j].pText);
		}

		Tools_Free((void **) &aFundRes->pRowPro[i].pCol);
	}
	
	if (aFundRes->pColPro)
	{
		Tools_Free((void **) &aFundRes->pRowPro);
	}
	
	aFundRes->Page.nColCount = aFundRes->Page.nRowCount = aFundRes->Page.nRef = 0;
	Tools_Free(&aFundRes->Page.pPrePageUrl);
	Tools_Free(&aFundRes->Page.pNextPageUrl);
	Tools_Free(&aFundRes->Page.pCurPageUrl);
}

void QuoteDataLv_ParseTradingHours(QUOTELV_TRADING_HOURS *pTradingHours, char *pXml)
{
	XML_NODE *pNode;
	XML_NODE *pTemp;
	char *pSrc;
	pSrc = pXml;
	pNode = XmlTools_Encrypt(&pSrc);
	
	
	if (pNode) {

		char *pText;
		/*查找市场*/
		pTemp = XmlTools_GetLeafNode(pNode, "Market");
		pTradingHours->nMarketNum = 0;
		pTradingHours->maxMinuteCount = 0;
		while (pTemp) {
			//逐市场解析
			pText = XmlTools_GetOptionValue(pTemp->pOption, "firstopen");
			if (pText) {
				pTradingHours->marketTrading[pTradingHours->nMarketNum].firstOpen = _a2i(pText);
			}
			pText = XmlTools_GetOptionValue(pTemp->pOption, "firstclose");
			if (pText) {
				pTradingHours->marketTrading[pTradingHours->nMarketNum].firstClose = _a2i(pText);
			}
			pText = XmlTools_GetOptionValue(pTemp->pOption, "secondopen");
			if (pText) {
				pTradingHours->marketTrading[pTradingHours->nMarketNum].secodeOpen = _a2i(pText);
			}
			pText = XmlTools_GetOptionValue(pTemp->pOption, "secondclose");
			if (pText) {
				pTradingHours->marketTrading[pTradingHours->nMarketNum].secodeClose = _a2i(pText);
			}
			pText = XmlTools_GetOptionValue(pTemp->pOption, "midscale");
			if (pText) {
				pTradingHours->marketTrading[pTradingHours->nMarketNum].midscale = _a2i(pText);
			}
			pText = XmlTools_GetOptionValue(pTemp->pOption, "id");
			if (pText) {
				pTradingHours->marketTrading[pTradingHours->nMarketNum].marketID = _a2i(pText);
			}
			
			//计算开市时间
			pTradingHours->marketTrading[pTradingHours->nMarketNum].minuteCount = CalcTimeDiffer(pTradingHours->marketTrading[pTradingHours->nMarketNum].firstOpen, pTradingHours->marketTrading[pTradingHours->nMarketNum].firstClose)
			+
			CalcTimeDiffer(pTradingHours->marketTrading[pTradingHours->nMarketNum].secodeOpen, pTradingHours->marketTrading[pTradingHours->nMarketNum].secodeClose)
			+2;
			
			/*取最大分钟*/
			pTradingHours->maxMinuteCount = max(pTradingHours->maxMinuteCount, pTradingHours->marketTrading[pTradingHours->nMarketNum].minuteCount);
			
			pTradingHours->nMarketNum++;
			
			//解析下一市场
			pTemp = XmlTools_GetLeafNodeNext(pTemp, "Market");
		}
		
		XmlTools_Free(pNode);
	}
}

QUOTELV_TRADING_HOURS_ITEM* QuoteDataLv_GetTradingHoursItem(QUOTELV_TRADING_HOURS *pTradingHours, int marketID)
{
	for (int i=0; i<pTradingHours->nMarketNum; i++) {
		if (pTradingHours->marketTrading[i].marketID==marketID) {
			return &pTradingHours->marketTrading[i];
		}
	}
	
	return NULL;
}


void QuoteDataLV_ParseFundMinData(char* aSrc, QUOTELV_FUND_MIN_RES *aFundMinRes)
{
	char *pSrc = (char*)aSrc;
	
	if (pSrc == NULL) {
		return;
	}
	
	int nPos = 0;
	aFundMinRes->nPointCount = 0;
	memset(&aFundMinRes->codeinfo, 0x00, sizeof(CODELV_INFO));
	
	//解股票信息
	QuoteDataLV_ParseStockInfo(pSrc, &aFundMinRes->codeinfo, &nPos);
	
	//分时点个数
	aFundMinRes->nPointCount = BytesToShort(pSrc, nPos);
	nPos += 2;
	
	for(int i=0; i<aFundMinRes->nPointCount; i++)
	{
		aFundMinRes->data[i].nDate = BytesToInt(pSrc, nPos);
		nPos+=4;
		aFundMinRes->data[i].nCur = BytesToFloat(pSrc, nPos);
		nPos+=4;
	}
}
